radian-software / straight.el

๐Ÿ€ Next-generation, purely functional package manager for the Emacs hacker.
MIT License
2.69k stars 150 forks source link

unrecognized keyword :straight with built in version of use-package #1035

Open yilkalargaw opened 1 year ago

yilkalargaw commented 1 year ago

What's wrong

I recently compiled Emacs from source. It has built in use-package. When trying to run my setup it fails with the error about unrecognized keyword :straight

Directions to reproduce

;;; package --- Summary
;;; Commentary:
;;; Code:

;;(package-initialize)

(let ((file-name-handler-alist nil))
  (require 'package)

(setq straight-repository-branch "develop")
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package 'use-package)

(use-package dash
  :straight t)

(use-package f
  :straight t)

(use-package async ;; :defer t
  :straight t)

(provide 'init))

;;; init.el ends here


### Version information

* Emacs version:
   This is GNU Emacs 30.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version 3.24.35, cairo version 1.17.6) of 2022-12-22

* Operating system:
  Linux fedora 6.0.15-300.fc37.x86_64
progfolio commented 1 year ago

I was able to get it to work via the following:

Test Case ```emacs-lisp (straight-bug-report :pre-bootstrap (require 'use-package-core) :post-bootstrap (use-package doct :straight t)) ```
Output ```emacs-lisp Bootstrapping straight.el... Bootstrapping straight.el...done Looking for gnu-elpa-mirror recipe โ†’ Cloning melpa... Looking for gnu-elpa-mirror recipe โ†’ Cloning melpa...done Looking for nongnu-elpa recipe โ†’ Cloning gnu-elpa-mirror... Looking for nongnu-elpa recipe โ†’ Cloning gnu-elpa-mirror...done Looking for emacsmirror-mirror recipe โ†’ Cloning nongnu-elpa... Looking for emacsmirror-mirror recipe โ†’ Cloning nongnu-elpa...done Looking for emacsmirror-mirror recipe โ†’ Cloning el-get... Looking for emacsmirror-mirror recipe โ†’ Cloning el-get...done Looking for straight recipe โ†’ Cloning emacsmirror-mirror... Looking for straight recipe โ†’ Cloning emacsmirror-mirror...done Building straight... Building straight...done Test run with version: prerelease (HEAD -> develop, origin/develop) e407ed5 2022-12-26 Cloning doct... Cloning doct...done Building doct... Building doct...done Packages: "straight" n/a develop e407ed5 2022-12-26 "org-elpa" n/a n/a "melpa" n/a master fbc5475f 2022-12-27 "gnu-elpa-mirror" n/a master eb11995 2022-12-15 "nongnu-elpa" n/a main b552c02813 2022-12-21 "el-get" melpa master 11affb52 2022-12-28 "emacsmirror-mirror" n/a master ec300b5 2022-12-27 "doct" melpa master 506c22f 2022-08-12 ```

This is because straight-use-package-mode internally uses with-eval-after-load to set up its integration. Adding (require use-package-core) prior to straight's bootstrap snippet should work.

yilkalargaw commented 1 year ago

Thank you @progfolio adding (require 'use-package-core) before bootstrap and (use-package doct :straight t) worked for me. It might be worth adding it to the documentation if it is a must do when using builtin use-package.

yilkalargaw commented 1 year ago

Sorry I jumped the gun. It just cloned melpa and non-gnu-elpa and reverted back to the previous errors.

progfolio commented 1 year ago

Please try evaluating the test case from above in your *scratch* buffer:

https://github.com/radian-software/straight.el/issues/1035#issuecomment-1367081185

When it finishes running the *straight-bug-report-process* buffer should pop up. Please copy the entire buffer contents of that buffer here.

yilkalargaw commented 1 year ago

It said that lexial binding was required so I run (setq lexical-binding t) before evaluating it.

yilkalargaw commented 1 year ago
Test Case ```emacs-lisp (straight-bug-report :pre-bootstrap (require 'use-package-core) :post-bootstrap (use-package doct :straight t)) ```
Output ```emacs-lisp Bootstrapping straight.el... Bootstrapping straight.el...done Looking for gnu-elpa-mirror recipe โ†’ Cloning melpa... Looking for gnu-elpa-mirror recipe โ†’ Cloning melpa...done Looking for nongnu-elpa recipe โ†’ Cloning gnu-elpa-mirror... Looking for nongnu-elpa recipe โ†’ Cloning gnu-elpa-mirror...done Looking for emacsmirror-mirror recipe โ†’ Cloning nongnu-elpa... Looking for emacsmirror-mirror recipe โ†’ Cloning nongnu-elpa...done Looking for emacsmirror-mirror recipe โ†’ Cloning el-get... Looking for emacsmirror-mirror recipe โ†’ Cloning el-get...done Looking for straight recipe โ†’ Cloning emacsmirror-mirror... Looking for straight recipe โ†’ Cloning emacsmirror-mirror...done Building straight... Building straight...done Test run with version: prerelease (HEAD -> develop, origin/develop) e407ed5 2022-12-26 Cloning doct... Cloning doct...done Building doct... Building doct...done Packages: "straight" n/a develop e407ed5 2022-12-26 "org-elpa" n/a n/a "melpa" n/a master fbc5475f 2022-12-27 "gnu-elpa-mirror" n/a master eb11995 2022-12-15 "nongnu-elpa" n/a main b552c02813 2022-12-21 "el-get" melpa master 11affb52 2022-12-28 "emacsmirror-mirror" n/a master ec300b5 2022-12-27 "doct" melpa master 506c22f 2022-08-12 ```
progfolio commented 1 year ago

The test appears to have passed. What does your init file currently look like?

yilkalargaw commented 1 year ago

Currently I am running the config I mentioned above because I'm trying to start from scratch. I'll try it another machine and report if the issue persists.

bramadams commented 1 year ago

Was there any definitive solution for this issue? Running straight.el on the latest Emacs 29 version only works consistently when using my non-bytecompiled init.el file.

When loading with my byte-compiled init.elc, the native compilation yields the same error messages as mentioned above (e.g., "Error (use-package): Failed to parse package paradox: use-package: Unrecognized keyword: :straight"). The next time I restart Emacs, the initialization process encounters the following error: "Warning (initialization): An error occurred while loading โ€˜/Users/bram/.emacs.d/eln-cache/29.0.60-4bf8ba72/init-563b6df7-97eefad5.elnโ€™:".

I tried with and without the suggested workaround ("(require 'use-package-core)").

progfolio commented 1 year ago

@bramadams: See https://www.gnu.org/software/emacs/manual/html_node/elisp/Compiling-Macros.html

You'd likely have to wrap some forms in eval-and-compile or eval-when-compile to get that working. Honestly, I wouldn't recommend compiling your init file. It's more trouble than it's worth. That's the official consensus, too:

https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html

bramadams commented 1 year ago

Thanks a lot, @progfolio, this suggestion got it to work!

My full initialization code to make byte/native compilation work with straight.el on Emacs 29 (23/03/2023 snapshot):

(eval-and-compile
  (defvar bootstrap-version)
  (setq straight-repository-branch "develop") ; TEMPORARY issue with straight, see https://jeffkreeftmeijer.com/emacs-straight-use-package/
  (let ((bootstrap-file
         (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
        (bootstrap-version 6))
    (unless (file-exists-p bootstrap-file)
      (with-current-buffer
          (url-retrieve-synchronously
           "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
           'silent 'inhibit-cookies)
        (goto-char (point-max))
        (eval-print-last-sexp)))
    (load bootstrap-file nil 'nomessage))

  ;; Install use-package
  (straight-use-package '(use-package :type built-in))
  (require 'bind-key)
  (setq straight-use-package-by-default t))
lebensterben commented 1 year ago

I can confirm @bramadams 's solution works. But as @progfolio points out, it's better not to byte compile the init file.

bramadams commented 1 year ago

Having read the Emacs manual link @progfolio mentioned, I got a feeling I should try out disabling byte-compilation of my init file, thanks for the encouragement @lebensterben :-)

raxod502 commented 1 year ago

Yeah, you can definitely byte-compile the init-file, but it takes special handling and custom code to make it work right. Otherwise you'll get all manner of problems. https://github.com/radian-software/radian is one reference configuration for taking care of this with straight.el.