;;; Code:

;;; settings for package archives
(require 'package)
(setq package-check-signature nil
      load-prefer-newer t)
(setq package-archives '(("gnu"    . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
                         ("nongnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/nongnu/")
                         ("melpa"  . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))

;;; initialize the packages, avoiding a re-initialization
(unless (bound-and-true-p package--initialized) ;; To avoid warnings on 27

(unless package-archive-contents

;; settings for use-package package
(unless (package-installed-p 'use-package)
  (package-install 'use-package))

;; configure use-package prior to loading it
  (setq use-package-always-ensure t
        use-package-always-defer t
        use-package-expand-minimally t)
  (require 'use-package))

(use-package gnu-elpa-keyring-update
	:defer 4)
(use-package diminish
	:defer 4)
(use-package delight
	:defer 4)

(provide 'init-elpa)


(unless package-archive-contents


2 个赞

M-x use-package-report 能够大体列出各个包的加载时间:


1 个赞

抱歉这几天有事才回复,我试了一下并没什么效果 ::

;;; initialize the packages, avoiding a re-initialization
(unless (bound-and-true-p package--initialized) ;; To avoid warnings on 27

那就是 (package-initialize) 这句花了 1s 多,注释掉试试

emacs27+ 不需要package-initialize.


例如我的设置代码考虑了从命令行启动emacs的可能, 还设置package-quickstart t, 这些技巧你自己摸索要很长时间,

(defun my-initialize-package ()
  "Package loading optimization.  No need to activate all the packages so early."
  ;; @see https://www.gnu.org/software/emacs/news/NEWS.27.1
  ;; ** Installed packages are now activated *before* loading the init file.
  ;; As a result of this change, it is no longer necessary to call
  ;; `package-initialize' in your init file.

  ;; Previously, a call to `package-initialize' was automatically inserted
  ;; into the init file when Emacs was started.  This call can now safely
  ;; be removed.  Alternatively, if you want to ensure that your init file
  ;; is still compatible with earlier versions of Emacs, change it to:

  ;; However, if your init file changes the values of `package-load-list'
  ;; or `package-user-dir', or sets `package-enable-at-startup' to nil then
  ;; it won't work right without some adjustment:
  ;; - You can move that code to the early init file (see above), so those
  ;;   settings apply before Emacs tries to activate the packages.
  ;; - You can use the new `package-quickstart' so activation of packages
  ;;   does not need to pay attention to `package-load-list' or
  ;;   `package-user-dir' any more.
  ;; "package-quickstart.el" converts path in `load-path' into
  ;; os dependent path, make it impossible to share same emacs.d between
  ;; Windows and Cygwin.
  (unless (or *win64* *cygwin*)
    ;; you need run `M-x package-quickstart-refresh' at least once
    ;; to generate file "package-quickstart.el'.
    ;; It contains the `autoload' statements for all packages.
    (setq package-quickstart t))

  ;; esup need call `package-initialize'
  ;; @see https://github.com/jschaf/esup/issues/84
  (when (or (featurep 'esup-child)
            (fboundp 'profile-dotemacs)

3 个赞