SystemCrafters / crafted-emacs

A sensible base Emacs configuration.
MIT License
739 stars 117 forks source link

use-package failed on craftedv2alpha branch with emacs 29 #275

Closed leira closed 1 year ago

leira commented 1 year ago

Hi, I'm trying to use the crafted-emacs' craftedv2alpha branch. I simply used the early-init-example.el and init-example.el in my emacs.d. Emacs started well. I want to add some of my own modules using use-package, as use-package is already part of emacs 29. But use-package macro failed to eval. Here are the code and backtrace:

(use-package meow
  :demand t
  :ensure t)
Debugger entered--Lisp error: (invalid-function '(("gnu" . 99) ("nongnu" . 80) ("stable" . 70) ("melpa" . 0)))
  ('(("gnu" . 99) ("nongnu" . 80) ("stable" . 70) ("melpa" . 0)))
  eval(('(("gnu" . 99) ("nongnu" . 80) ("stable" . 70) ("melpa" . 0))))
  custom-theme-recalc-variable(package-archive-priorities)
  enable-theme(user)
  enable-theme(use-package)
  byte-code("\301\302!\210\301\303!\210\301\304!\210\305\306\307\310\211$\210\311\306!\210\312\306\10\"\20\313\306\310\314\315\316\317\320\321\322&\11\207" [custom-enabled-themes require bytecomp cl-lib tabulated-list custom-declare-theme use-package use-package-theme nil enable-theme remq custom-declare-group "A `use-package' declaration for simplifying your `..." :group initialization :link (custom-manual "(use-package) Top") :version "29.1"] 10)
  macroexpand((use-package meow :demand t :ensure t))
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  command-execute(eval-last-sexp)

Actually, c-h f use-package also gives error (invalid-function '(("gnu" . 99) ("nongnu" . 80) ("stable" . 70) ("melpa" . 0))). The same code works fine with emacs -Q.

It seems have something to do with the code in crafted-early-init-config.el, but I'm not familiar with elisp enough to figure out how:

(customize-set-variable 'package-archive-priorities
                        '(("gnu"    . 99)   ; prefer GNU packages
                          ("nongnu" . 80)   ; use non-gnu packages if
                                            ; not found in GNU elpa
                          ("stable" . 70)   ; prefer "released" versions
                                            ; from melpa
                          ("melpa"  . 0)))  ; if all else fails, get it
                                            ; from melpa
leira commented 1 year ago

I dig a bit into it.

(enable-theme 'use-package) is part of https://github.com/jwiegley/use-package/blob/master/use-package-core.el

enable-theme function has this code, that's where enable-theme(user) in the stack is from:

  (unless (eq theme 'user)
    (setq custom-enabled-themes
      (cons theme (remq theme custom-enabled-themes)))
    ;; Give the `user' theme the highest priority.
    (enable-theme 'user))

And the code before in enable-theme is like:

  (let ((settings (get theme 'theme-settings)) ; '(prop symbol theme value)
        ;; We are enabling the theme, so don't inhibit enabling it.  (Bug#34027)
        (custom--inhibit-theme-enable nil))
    ;; Loop through theme settings, recalculating vars/faces.
    (dolist (s settings)
      (let* ((prop (car s))
             (symbol (cadr s))
             (spec-list (get symbol prop))
             (sv (get symbol 'standard-value))
             (val (and (boundp symbol) (symbol-value symbol))))

...

    (cond
     ((eq prop 'theme-face)
      (custom-theme-recalc-face symbol))
     ((eq prop 'theme-value)
      ;; Ignore `custom-enabled-themes' and `custom-safe-themes'.
      (unless (memq symbol '(custom-enabled-themes custom-safe-themes))
        (custom-theme-recalc-variable symbol)))))))

I tried (get 'user 'theme-settings), I got

((theme-value package-archive-priorities user ('(("gnu" . 99) ("nongnu" . 80) ("stable" . 70) ("melpa" . 0)))) (theme-value scroll-conservatively user (101)) (theme-value switch-to-buffer-in-dedicated-window user ('pop)) (theme-value completions-detailed user (t)) (theme-value kill-do-not-save-duplicates user (t)) (theme-value completion-category-overrides user ('(...))) (theme-value tab-always-indent user ('complete)) (theme-value switch-to-buffer-obey-display-actions user (t)) (theme-value mouse-wheel-progressive-speed user (nil)) (theme-value ibuffer-movement-cycle user (nil)) (theme-value load-prefer-newer user (t)) (theme-value scroll-margin user (0)) ...)

This is how package-archive-priorities get into the picture. But I'm don't know what it means.

(get 'user 'theme-settings) in emacs -Q returns nil.

leira commented 1 year ago

hmm, restart emacs seems working. It seems just evaling (use-package meow) directly in emacs caused the problem...

leira commented 1 year ago

It works with restart Emacs, so close it.