I want to update Emacs from the command line so I created the following function to help with this:
;;; update.el -- Update Emacs from the command line
(defun update-emacs ()
"Update Emacs without interaction, to be used from the command line."
(defun perform-emacs-update ()
(switch-to-buffer "*Packages*")
(declare-function package-menu-mark-upgrades "package.el.gz")
(declare-function package-menu-execute "package.el.gz")
(package-menu-mark-upgrades)
(package-menu-execute t))
(add-hook 'package--post-download-archives-hook 'perform-emacs-update)
(package-list-packages))
(provide 'update-emacs)
Then I run Emacs with these parameters:
$ emacs --batch --eval '(load "~/.emacs.d/update.el")' --eval '(update-emacs)'
However it doesn't run the hook for some reason. I get this output instead
Loading ~/.emacs.d/update.el (source)... Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
This code works fine when I execute it from an already running Emacs. How can I get it to run in batch mode?