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

What's the best way of doing this?

share|improve this question
    
Here is a command fo upgrade all outdated packages: github.com/Malabarba/paradox/blob/2.3.5/paradox.el#L165-L181 (replace all paradox with package). – xuchunyang Sep 6 '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 7 '15 at 2:31
up vote 8 down vote accepted

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.

share|improve this answer
    
Nice. I'm going to use this with a slight variation that doesn't prompt before upgrading the packages. – PythonNut Sep 7 '15 at 15:03
    
Is there any particular reason why you do (y-or-n-p (message ..)) instead of just (y-or-n-p ...)? – PythonNut Sep 8 '15 at 21:19
    
@PythonNut, Well I need to construct prompt message, I don't remember now why I use message, it seems it can be done with format just as well. – Mark Karpov Sep 8 '15 at 21:55
    
Ah yes. I meant using format. Obviously you can't do it without any sort of string interpolation. – PythonNut Sep 8 '15 at 21:58

You can use auto-update-package.

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))
share|improve this answer
    
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 7 '15 at 4:05

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))
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.