Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectrum with use-package (compiler warning) #410

Open
jsirex opened this issue Jan 28, 2021 · 10 comments
Open

selectrum with use-package (compiler warning) #410

jsirex opened this issue Jan 28, 2021 · 10 comments

Comments

@jsirex
Copy link

jsirex commented Jan 28, 2021

(setq package-quickstart t)
...

(use-package selectrum
  :init
  (selectrum-mode +1))

Macro expanded to

(progn
  (use-package-ensure-elpa 'selectrum
                           '(t)
                           'nil)
  (selectrum-mode 1))

During compilation I got:

init.el:607:1: Warning: the function ‘selectrum-mode’ might not be defined at runtime.

It does not work until I re-active it by off-on mode. I checked that autoload is present

GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0) of 2021-01-22, unofficial emacs-snapshot build: http://emacs.secretsauce.net
@clemera
Copy link
Collaborator

clemera commented Jan 28, 2021

Thanks! You meant during compilation of your init file? I think compiling your init file is generally discouraged, selectrum-mode is defined within the autoload file itself to allow enabling it without requiring to load the selectrum file itself.

@jsirex
Copy link
Author

jsirex commented Jan 28, 2021

I fixed off-on mode issue by removing emacs-desktop and starting from scratch. However, warning is still here

@clemera
Copy link
Collaborator

clemera commented Jan 28, 2021

If you want to keep compiling your init file (I wouldn't recommend it) and want to get rid of the warning you could probably add a (declare-function selectrum-mode "selectrum" nil t) to avoid it.

@minad
Copy link
Contributor

minad commented Jan 28, 2021

@clemera

I think compiling your init file is generally discouraged

If you want to keep compiling your init file (I wouldn't recommend it)

I disagree ;) If you have heavy macro expansion in your init.el it is worth it. Furthermore I am using a heap dump, at this point it starts to matter.

@jsirex

This warning is mostly harmless but can be worked around by defining :function in use-package as far as I know, or use declare-function as @clemera proposed. But I have multiple of these warnings when compiling my init.el and it is not an issue.

@minad
Copy link
Contributor

minad commented Jan 28, 2021

There is one more thing about compilation I think - if you evaluate lambdas the interpreter does not perform a proper lexical closure analysis it seems and creates monster closures. I had this issue when debugging consult--read and evaluating it. The bytecode compiler in contrast gets this right. Therefore the more you compile the better ;)

@clemera
Copy link
Collaborator

clemera commented Jan 28, 2021

I guess it depends how you organize your config, I have to add that I put any "real code" outside the init file and compile those files, too.

@minad
Copy link
Contributor

minad commented Jan 28, 2021

Okay, sure that is a valid approach too. I also straced emacs startup for the fun of it (it is horrible btw) and it only loads the init.elc and nothing else in my case. But my config is more of a mess than yours I think. I rather try to move real code to real packages and avoid creating multiple config-xyz.el files as is very common in many popular configurations.

@jsirex
Copy link
Author

jsirex commented Jan 28, 2021

I'm using single init.el with sorted use-package macro.
I'm also using packages quickstart feature. It merges all autoloads in one file and compiles them.

(use-package selectrum
  :functions 'selectrum-mode
  :init
  (selectrum-mode +1))

This also does not help. I tried to regenerate package-quickstart.el and have noticed another warning:

package-quickstart.el:2250:2170: Warning: defcustom for ‘selectrum-mode’ fails
    to specify containing group

@clemera
Copy link
Collaborator

clemera commented Jan 28, 2021

This also does not help. I tried to regenerate package-quickstart.el and have noticed another warning:

Thanks, I added the group in e930b10. I missed that because for defcustom specified in the same file as defgroup you don't need it at all.

@clemera clemera changed the title selectrum with use-package selectrum with use-package (compiler warning) Jan 28, 2021
@raxod502
Copy link
Member

raxod502 commented Feb 26, 2021

I think compiling your init file is generally discouraged

Just to throw in my two cents to this discussion, the bulk of my configuration is in a separate file and byte-compiled, and my init.el is mostly a wrapper to add error handling as well as automatically detect when the main config file .elc is outdated, and prevent it from being loaded in that case.

Here is the code for that: https://github.com/raxod502/radian/blob/193c702c810562c770a0e09d787eb9bd3d93cda2/emacs/init.el#L82-L115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants