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

How to use use-package preface along with straight.el #728

Closed
declantsien opened this issue Mar 27, 2021 · 5 comments
Closed

How to use use-package preface along with straight.el #728

declantsien opened this issue Mar 27, 2021 · 5 comments

Comments

@declantsien
Copy link

According to use-package document
https://github.com/jwiegley/use-package/blob/e6b4bf8458f94227ed64df6e8e873d147e42916f/use-package-core.el#L1560-L1562

Code defined in preface block can be seen by the byte-compiler.

I want to use some autoload function from doom repo, but I keep getting
error invalid function: quiet!

(use-package testtmux
  :preface
  (defun doom-project-root() (projectile-project-root))
  (defmacro quiet! (&rest forms)
    `(progn ,@forms))
  :straight (:type git :files ("modules/tools/tmux/autoload/tmux.el") :host github :repo "hlissner/doom-emacs"))
@progfolio
Copy link
Contributor

progfolio commented Mar 28, 2021

As I understand it, use-package's :preface keyword wraps its forms in eval-and-compile. You can verify this by using macroexpand on your example:

(progn
  (straight-use-package
   '(testtmux :type git :files
              ("modules/tools/tmux/autoload/tmux.el")
              :host github :repo "hlissner/doom-emacs"))
  (eval-and-compile
    (defun doom-project-root nil
      (projectile-project-root))
    (defmacro quiet!
        (&rest forms)
      `(progn ,@forms)))
  (require 'testtmux nil nil))

Notice that the :preface forms are evaluated after the call to staright-use-package in the expansion. Bear in mind that Doom modifies and builds off straight.el as well. I'm not too familiar with everything it does because I don't use Doom myself. What is it specifically you are trying to achieve? Can you provide an example using straight-bug-report that exhibits similar behavior?

@declantsien
Copy link
Author

Thanks for you response. This is actually not a bug report but a question.

For the record, this is an edge use case.

The problem here is that this is not real package(Not self contained or with dependencies declaration or with a provide ).

There are some undefined functions/macros(which I defined later).

I think straight byte compiled package files without knowledge which is a function and which is a function.
Which can be solved by disable byte-compile:build (:not compile :not native-compile) .
Customizing how packages are built / #357

Feel free to close this issue though.

@raxod502
Copy link
Member

Is it also possible to solve your issue by moving the defun and defmacro above the use-package form, rather than inside it under :preface? The way use-package is written, it runs :preface after invoking the package manager, whereas you want to define some stuff beforehand.

@declantsien
Copy link
Author

Nah, just tried.
As far as I read straight.el source code

https://github.com/raxod502/straight.el/blob/develop/straight.el#L4837-L4838

straight.el starts a new emacs process for recipe byte-compilation.
And it can only see information defined in the recipe like dependencies.

Thanks for this awesome package. Liked.

@raxod502
Copy link
Member

raxod502 commented Apr 4, 2021

Ah yes, good point. I had forgotten we made that change, which would indeed break this. I guess there could be a use case for providing to straight.el additional forms that should be evaluated inside the byte-compilation environment. But unless other people request the feature also, just disabling byte-compilation seems like a more practical workaround.

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

No branches or pull requests

3 participants