Use-package 自动安装插件的问题

use package 同时使用 ensure和defer 是不是不会自动安装?

会,自己试试最清楚。

ensure是确保包被 安装 ,defer是延迟包的 加载

那应该是我配置的问题了

手动安装好了能使用,但我使用ensure t 和defer t的时候就不会自动安装,报错误

(file-missing “Cannot open load file” “没有那个文件或目录” “editorconfig”)

默认安装在elpa目录下,你也可以通过load-path设置

我知道这个路径问题,现在是自动安装的问题。按照我的配置, use-package 使用ensure 和defer 不能自动安装

你的配置是什么?

使用 use-package 时将其展开来确认是不是你想要的结果,我估计多数人都不明白 use-package 究竟是怎么回事(我也不明白)。

:ensure 关键字会自动安装系统没有的 package。每个包必加,或者直接设定全局添加 (setq use-package-always-ensure t)

:defer 关键字实现延迟加载。除非确定知道如何唤醒,否则慎用。

仔细读手册,我觉得你应该是 defer 后没唤醒指令。

https://phenix3443.github.io/notebook/emacs/use-package-manual.html

怎么展开?我还不会

M-x info C-s elisp

(info “(elisp)Expansion”) C-x C-e

M-x emacs-lisp-macroexpand (需要至少 Emacs 25.1),比如下面的表达式,光标放到开头,执行这个命令

(cl-incf x)

会得到:

(setq x
      (1+ x))

除了 emacs-lisp-macroexpand,也可以用

另外,印象中 use-package 也自带了 Debug 的功能,应该也有展开的功能。

1 个赞
(use-package editorconfig
  :ensure t
  :defer t
  :hook (prog-mode . editorconfig-mode))

我在去学习学习

我没有定制过 use-package,你的配置默认展开得到(第一个表达就是安装这个包):

(progn
  (use-package-ensure-elpa 'editorconfig
                           '(t)
                           'nil)
  (defvar use-package--warning311
    (function
     (lambda
       (keyword err)
       (let
           ((msg
             (format "%s/%s: %s" 'editorconfig keyword
                     (error-message-string err))))
         (display-warning 'use-package msg :error)))))
  (condition-case-unless-debug err
      (progn
        (unless
            (fboundp 'editorconfig-mode)
          (autoload
            (function editorconfig-mode)
            "editorconfig" nil t))
        (add-hook 'prog-mode-hook
                  (function editorconfig-mode)))
    (error
     (funcall use-package--warning311 :catch err))))

我好像知道原因了,我的配置被compile过,将elc文件删了过后就没有问题了

加载过期的 ELC 时 Emacs 会发出提示,类似于:

Source file `foo.el' newer than byte-compiled file
1 个赞