(prefix-numeric-value current-prefix-arg))))
(previous-matching-history-element regexp (- n)))
+(defvar minibuffer-temporary-goal-position nil)
+
(defun next-history-element (n)
"Insert the next element of the minibuffer history into the minibuffer."
(interactive "p")
(error "End of history; no default available")))
(if (> narg (length (symbol-value minibuffer-history-variable)))
(error "Beginning of history; no preceding item"))
+ (unless (or (eq last-command 'next-history-element)
+ (eq last-command 'previous-history-element))
+ (let ((prompt-end (field-beginning (point-max))))
+ (set (make-local-variable 'minibuffer-temporary-goal-position)
+ (cond ((<= (point) prompt-end) prompt-end)
+ ((eobp) nil)
+ (t (point))))))
(goto-char (point-max))
(delete-field)
(setq minibuffer-history-position narg)
(let ((print-level nil))
(prin1-to-string elt))
elt))
- (goto-char (field-beginning)))))
+ (goto-char (or minibuffer-temporary-goal-position (point-max))))))
(defun previous-history-element (n)
"Inserts the previous element of the minibuffer history into the minibuffer."