Straight.el: How to use use-package preface along with straight.el

Created on 27 Mar 2021  路  5Comments  路  Source: raxod502/straight.el

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"))
byte compilation support use-package

All 5 comments

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?

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.

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.

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raxod502 picture raxod502  路  3Comments

aspiers picture aspiers  路  4Comments

progfolio picture progfolio  路  3Comments

eflanigan00 picture eflanigan00  路  4Comments

mclearc picture mclearc  路  4Comments