diff --git a/lisp/simple.el b/lisp/simple.el index ea3a495fbc..1b96bce773 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2140,7 +2140,16 @@ previous-line-or-history-element (current-column))))) (condition-case nil (with-no-warnings - (previous-line arg)) + ;; If the history element consists of a single line longer + ;; than window-width, move by logical lines to hit + ;; beginning-of-buffer immediately and get the previous + ;; history element. Otherwise, move by visual lines. + (if (and (save-excursion + (end-of-line) + (> (current-column) (window-width))) + (= (line-number-at-pos) 1)) + (previous-logical-line arg) + (previous-line arg))) (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. @@ -2162,10 +2171,9 @@ previous-line-or-history-element ;; would move to the previous history element, not to a possible upper ;; visual line from the end of logical line in `line-move-visual' mode. (end-of-visual-line) - ;; Since `end-of-visual-line' puts the cursor at the beginning - ;; of the next visual line, move it one char back to the end - ;; of the first visual line (bug#22544). - (unless (eolp) (backward-char 1))))))) + ;; If the line extends beyond window-width, go to its logical end, + ;; since that is the natural target for editing history elements. + (unless (eolp) (end-of-line))))))) (defun next-complete-history-element (n) "Get next history element which completes the minibuffer before the point.