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

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

Open
yilkalargaw opened this issue Dec 29, 2022 · 14 comments
Open

Comments

@yilkalargaw
Copy link

yilkalargaw commented Dec 29, 2022

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

  • build Emacs directrly from emacs/HEAD
  • delete previous emacs.d to start from a blank slate
  • try the following minimal config
;;; 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
  • It fails with the following errors
⛔ Error (use-package): Failed to parse package dash: use-package: Unrecognized keyword: :straight
⛔ Error (use-package): Failed to parse package f: use-package: Unrecognized keyword: :straight
⛔ Error (use-package): Failed to parse package async: use-package: Unrecognized keyword: :straight

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

@yilkalargaw yilkalargaw changed the title Straight fails with emacs head (30) when using the included use-package Straight fails with emacs/head (30) when using the included use-package Dec 29, 2022
@progfolio
Copy link
Contributor

progfolio commented Dec 29, 2022

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

Test Case
(straight-bug-report
  :pre-bootstrap 
  (require 'use-package-core)
  :post-bootstrap 
  (use-package doct :straight t))
  • Test run at: 2022-12-29 00:53:38
  • system-type: gnu/linux
  • straight-version: prerelease (HEAD -> develop, origin/develop) 05caec1 2022-12-22
  • emacs-version: GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.35, cairo version 1.17.6) of 2022-12-18
Output
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.

@progfolio progfolio changed the title Straight fails with emacs/head (30) when using the included use-package unrecognized keyword :straight with built in version of use-package Dec 29, 2022
@yilkalargaw
Copy link
Author

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
Copy link
Author

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

@progfolio
Copy link
Contributor

progfolio commented Dec 29, 2022

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

#1035 (comment)

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

@yilkalargaw
Copy link
Author

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

@yilkalargaw
Copy link
Author

Test Case
(straight-bug-report
  :pre-bootstrap 
  (require 'use-package-core)
  :post-bootstrap 
  (use-package doct :straight t))
  • Test run at: 2022-12-29 11:36:59
  • system-type: gnu/linux
  • straight-version: prerelease (HEAD -> develop, origin/develop) e407ed5 2022-12-26
  • emacs-version: 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
Output
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
Copy link
Contributor

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

@yilkalargaw
Copy link
Author

yilkalargaw commented Dec 29, 2022

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
Copy link

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
Copy link
Contributor

@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
Copy link

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
Copy link

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

@bramadams
Copy link

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
Copy link
Member

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.

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

No branches or pull requests

5 participants