From: Eshel Yaron Date: Thu, 25 Apr 2024 07:25:48 +0000 (+0200) Subject: ; Simplify 'minibuffer-previous/next-line-or-call' X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1037da01ac47f75827f8b0113db2be1d4f8f2184;p=emacs.git ; Simplify 'minibuffer-previous/next-line-or-call' * lisp/simple.el (minibuffer-next-line-or-call) (minibuffer-previous-line-or-call): Cease restoring column after calling FUN, fixing cursor positioning in 'minibuffer-previous/next-line-or-completion'. --- diff --git a/lisp/simple.el b/lisp/simple.el index eaa546303f2..4ca2e4b9253 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3170,20 +3170,9 @@ Interactively, N is the prefix numeric argument and defaults to 1." "Move cursor vertically down ARG lines, or call function FUN." (interactive "^p") (or arg (setq arg 1)) - (let* ((old-point (point)) - ;; Don't add newlines if they have the mode enabled globally. - (next-line-add-newlines nil) - ;; Remember the original goal column of possibly multi-line input - ;; excluding the length of the prompt on the first line. - (prompt-end (minibuffer-prompt-end)) - (old-column (unless (and (eolp) (> (point) prompt-end)) - (if (= (line-number-at-pos) 1) - (max (- (current-column) - (save-excursion - (goto-char (1- prompt-end)) - (current-column))) - 0) - (current-column))))) + (let ((old-point (point)) + ;; Don't add newlines if they have the mode enabled globally. + (next-line-add-newlines nil)) (condition-case nil (with-no-warnings (next-line arg)) @@ -3191,21 +3180,7 @@ Interactively, N is the prefix numeric argument and defaults to 1." ;; Restore old position since `line-move-visual' moves point to ;; the end of the line when it fails to go to the next line. (goto-char old-point) - (funcall fun arg) - ;; Reset `temporary-goal-column' because a correct value is not - ;; calculated when `next-line' above fails by bumping against - ;; the bottom of the minibuffer (bug#22544). - (setq temporary-goal-column 0) - ;; Restore the original goal column on the last line - ;; of possibly multi-line input. - (goto-char (point-max)) - (when old-column - (if (= (line-number-at-pos) 1) - (move-to-column (+ old-column - (save-excursion - (goto-char (1- (minibuffer-prompt-end))) - (current-column)))) - (move-to-column old-column))))))) + (funcall fun arg))))) (defun next-line-or-history-element (&optional arg) "Move cursor vertically down ARG lines, or to the next history element. @@ -3219,18 +3194,7 @@ next element of the minibuffer history in the minibuffer." "Move cursor vertically up ARG lines, or call function FUN." (interactive "^p") (or arg (setq arg 1)) - (let* ((old-point (point)) - ;; Remember the original goal column of possibly multi-line input - ;; excluding the length of the prompt on the first line. - (prompt-end (minibuffer-prompt-end)) - (old-column (unless (and (eolp) (> (point) prompt-end)) - (if (= (line-number-at-pos) 1) - (max (- (current-column) - (save-excursion - (goto-char (1- prompt-end)) - (current-column))) - 1) - (current-column))))) + (let ((old-point (point))) (condition-case nil (with-no-warnings (previous-line arg) @@ -3251,32 +3215,7 @@ next element of the minibuffer history in the minibuffer." ;; Restore old position since `line-move-visual' moves point to ;; the beginning of the line when it fails to go to the previous line. (goto-char old-point) - (funcall fun arg) - ;; Reset `temporary-goal-column' because a correct value is not - ;; calculated when `previous-line' above fails by bumping against - ;; the top of the minibuffer (bug#22544). - (setq temporary-goal-column 0) - ;; Restore the original goal column on the first line - ;; of possibly multi-line input. - (goto-char (minibuffer-prompt-end)) - (if old-column - (if (= (line-number-at-pos) 1) - (move-to-column (+ old-column - (save-excursion - (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)))))))) + (funcall fun arg))))) (defun previous-line-or-history-element (&optional arg) "Move cursor vertically up ARG lines, or to the previous history element.