Fixes a bug where saving a custom variable (e.g. package-selected-packages)
before reading the custom settings from dotspacemacs/emacs-custom-settings could
overwrite the stored settings.
In this case Spacemacs won't write custom variables to the
dotspacemacs/emacs-custom-settings variable.
Move setq and add-advice to spacemacs/initialize-custom-file which is now
called in spacemacs/init function just after dotspacemacs/user-init function.
New function `dotspacmacs/emacs-custom-settings` wrapping Emacs
custom settings sexps.
`dotspacemacs/emacs-custom-settings` is called just after the user
configuration (`dotspacemacs/user-config`)
Customize cannot write its auto-generated sexps inside a function, to
accomplish this we trick Emacs by setting the custom file to a file
in `.cache` directory, the path to this file is defined by the variable
`spacemacs--custom-file`. At the startup of Emacs we read this file
to insert its content inside the function
`dotspacemacs/emacs-custom-settings` in the dotfile, this is done in the
function `spacemacs/write-custom-settings-to-dotfile`.
I don't think we need to write the custom settings to the dotfile when
exiting Emacs as well, since we do it at startup at the very beginning
(i.e. before actually loading the dotfile) we should be OK.
Fixes#5170