diff --git a/lisp/simple.el b/lisp/simple.el index fa6e154004..96b56815cd 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2355,7 +2355,16 @@ next-line-or-history-element (current-column))))) (condition-case nil (with-no-warnings - (next-line arg)) + ;; If the history element consists of a single line longer + ;; than window-width, move by logical lines to hit + ;; end-of-buffer immediately and get the next history + ;; element. Otherwise, move by visual lines. + (if (and (save-excursion + (end-of-line) + (> (current-column) (window-width))) + (= (line-number-at-pos) 1)) + (next-logical-line arg) + (next-line arg)) (end-of-buffer ;; Restore old position since `line-move-visual' moves point to ;; the end of the line when it fails to go to the next line. @@ -2396,7 +2405,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. @@ -2416,17 +2434,14 @@ previous-line-or-history-element (goto-char (1- (minibuffer-prompt-end))) (current-column)))) (move-to-column old-column)) - (if (not line-move-visual) ; Handle logical lines (bug#42862) - (end-of-line) - ;; Put the cursor at the end of the visual line instead of the - ;; logical line, so the next `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)))))))) + ;; Put the cursor at the end of the logical line, even if + ;; it extends beyond window-width, since that is the + ;; natural target for editing history elements (bug#27191). + ;; The condition above makes sure the next + ;; `previous-line-or-history-element' will move to the + ;; previous history element regardless of the value of + ;; `line-move-visual'. + (end-of-line))))))) (defun next-complete-history-element (n) "Get next history element that completes the minibuffer before the point.