(minibuffer-text-before-history): New variable.
(minibuffer-history-initialize): New fn, on minibuffer-setup-hook.
(next-history-element, previous-matching-history-element):
Initialize minibuffer-text-before-history.
(next-history-element): Use minibuffer-text-before-history
as "position 0" of the history list.
Use minibuffer-default as position -1, if it is non-nil.
Simplify error logic for beginning and end of history.
(set-variable): Delete old definition (duplicate).