I want to declare all packages that I want to use in emacs in a init.el file. I wonder if its possible to load the missing packages with e.g. MELPA when I startup e
A bit of code in your init file can do that quite easily:
(setq my-onlinep nil)
(unless
(condition-case nil
(delete-process
(make-network-process
:name "my-check-internet"
:host "elpa.gnu.org"
:service 80))
(error t))
(setq my-onlinep t))
(setq my-packages
'(ack-and-a-half
ac-nrepl
... more packages here ...
web-mode
yaml-mode
yari
yasnippet))
(when my-onlinep
(package-refresh-contents)
(cl-loop for p in my-packages
unless (package-installed-p p)
do (package-install p)))
The online check is not really needed but helps to avoid getting a stuck Emacs startup when there is no internet connection.
For my full config see here: http://steckerhalter.co.vu/steckemacs.html#sec-2-5