package-autoremove如何确定要删除的软件包?


11

在更新当前软件包以运行package-autoremove时,经常会提示我,该软件包声称要删除过时或不必要的软件包。但是,它似乎总是删除(以及那些过时的软件包)我确实使用的两个软件包(即aurora-theme,我当前选择的主题和dired +)。

恐怕对于Emacs-Lisp来说我还是一个新手,我只是想知道是否有办法阻止软件包自动删除删除这些软件包,因此我不需要继续重新安装它们。

Answers:


7

来源在这里:https : //github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/package.el#L2113

它会删除所有不在“ packages-selected-packages”或某个依赖项中的软件包。

(defun package-autoremove ()
"Remove packages that are no more needed.
        Packages that are no more needed by other packages in
        `package-selected-packages' and their dependencies
        will be deleted."
(interactive)
;; If `package-selected-packages' is nil, it would make no sense to
;; try to populate it here, because then `package-autoremove' will
;; do absolutely nothing.
(when (or package-selected-packages
            (yes-or-no-p
            (format-message
            "`package-selected-packages' is empty! Really remove ALL packages? ")))
    (let ((removable (package--removable-packages)))
    (if removable
        (when (y-or-n-p
                (format "%s packages will be deleted:\n%s, proceed? "
                        (length removable)
                        (mapconcat #'symbol-name removable ", ")))
            (mapc (lambda (p)
                    (package-delete (cadr (assq p package-alist)) t))
                removable))
        (message "Nothing to autoremove")))))

(defun package--removable-packages ()
  "Return a list of names of packages no longer needed.
These are packages which are neither contained in
`package-selected-packages' nor a dependency of one that is."
  (let ((needed (cl-loop for p in package-selected-packages
                         if (assq p package-alist)
                         ;; `p' and its dependencies are needed.
                         append (cons p (package--get-deps p)))))
    (cl-loop for p in (mapcar #'car package-alist)
             unless (memq p needed)
             collect p)))

1
因此,此代码意味着,如果将包名称添加到package-selected-packages,则不会自动删除它。
zck 2015年

@zck是的。包装-可移动包装做到了这一点。
jiegec

还值得注意的是,package-selected-packages在安装和删除软件包时会自动更新。通常,您不需要直接修改它。如果您看到东西被自动删除,则它们很可能是作为您安装的东西的依赖项被拉进来的,然后又被删除的软件包。除了支持自动删除之外,当您将emacs配置复制到新机器并希望使用来安装所选软件包列表中的所有内容时,可以使用此变量package-install-selected-packages
glucas

1
@jiegec我的观点,写得不好,是解决用户的问题(“我怎么阻止autoremoved包”)是“包添加到package-selected-packages
ZCK

@zck是的。您说得对
jiegec
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.