16

I want my emacs to automatically upgrade all packages under certain conditions.

What's the best way of doing this?

PythonNut
  • 10,363
  • 2
  • 30
  • 76
  • Here is a command fo upgrade all outdated packages: https://github.com/Malabarba/paradox/blob/2.3.5/paradox.el#L165-L181 (replace all paradox with package). – xuchunyang Sep 06 '15 at 23:17
  • @xuchunyang Ah. I see that doesn't look too bad. If you make that an answer, I'd accept it. – PythonNut Sep 07 '15 at 02:31

3 Answers3

12

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.

Mark Karpov
  • 4,943
  • 1
  • 26
  • 54
9

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))
Chillar Anand
  • 4,102
  • 1
  • 24
  • 52
  • Hm... I'll keep this in mind, but the idea is to try automatically fixing packaged if they are broken. Depending on a package to do so is kinda nonsensical. :-) – PythonNut Sep 07 '15 at 04:05
2

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))
Stefan
  • 26,404
  • 3
  • 48
  • 85
Richard
  • 121
  • 2