diff --git a/lisp/simple.el b/lisp/simple.el index c878fdab92..680bfd7f43 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2472,14 +2472,24 @@ previous-line-or-history-element (save-excursion (goto-char (1- prompt-end)) (current-column))) - 0) + 1) (current-column))))) (condition-case nil (with-no-warnings (previous-line arg) ;; Avoid moving point to the prompt (when (< (point) (minibuffer-prompt-end)) - (signal 'beginning-of-buffer nil))) + ;; If there is minibuffer contents on the same line + (if (<= (minibuffer-prompt-end) + (save-excursion + (if (or truncate-lines (not line-move-visual)) + (end-of-line) + (end-of-visual-line)) + (point))) + ;; Move to the beginning of minibuffer contents + (goto-char (minibuffer-prompt-end)) + ;; Otherwise, go to the previous history element + (signal 'beginning-of-buffer nil)))) (beginning-of-buffer ;; Restore old position since `line-move-visual' moves point to ;; the beginning of the line when it fails to go to the previous line.