I want my emacs to automatically upgrade all packages under certain conditions.
What's the best way of doing this?
I want my emacs to automatically upgrade all packages under certain conditions.
What's the best way of doing this?
I'm not sure this is what you want (I don't know what you mean by “under
certain conditions”), but here is a function I use to upgrade all packages
without showing *Packages*
buffer, which I find annoying when I just want to
upgrade packages.
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
This is well-tried. It also prevents compilation buffers from popping up.
You can use auto-package-update.
Install it by M-x package-install auto-update-package
. It provides a function called auto-package-update-now
. You can write a simple if
condition and add that to your .emacs
.
(if your-condition
(auto-package-update-now))
The package is now called auto-package update. (Too low reputation to write it as a comment to the Chillar post above).
(Copied from his post and merged with this answer):
Install it by M-x package-install auto-package-update
. It provides a function called auto-package-update-now
. You can write a simple if condition and add that to your ~/.emacs
.
(if your-condition
(auto-package-update-now))