Function: next-line-completion

next-line-completion is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(next-line-completion &optional N)

Documentation

Move to completion candidate on the next line in the completions buffer.

With prefix argument N, move N lines forward (negative N means move backward).

Also see the completion-auto-wrap variable.

View in manual

Probably introduced at or before Emacs version 30.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun next-line-completion (&optional n)
  "Move to completion candidate on the next line in the completions buffer.
With prefix argument N, move N lines forward (negative N means move backward).

Also see the `completion-auto-wrap' variable."
  (interactive "p")
  (let (line column pos found)
    (when (and (bobp)
               (> n 0)
               (get-text-property (point) 'mouse-face)
               (not (get-text-property (point) 'first-completion)))
      (let ((inhibit-read-only t))
        (add-text-properties (point) (1+ (point)) '(first-completion t)))
      (setq n (1- n)))

    (if (get-text-property (point) 'mouse-face)
        ;; If in a completion, move to the start of it.
        (completion--move-to-candidate-start)
      ;; Try to move to the previous completion.
      (setq pos (previous-single-property-change (point) 'mouse-face))
      (if pos
          ;; Move to the start of the previous completion.
          (progn
            (goto-char pos)
            (unless (get-text-property (point) 'mouse-face)
              (goto-char (previous-single-property-change
                          (point) 'mouse-face nil (point-min)))))
        (cond ((> n 0) (setq n (1- n)) (first-completion))
              ((< n 0) (first-completion)))))

    (while (> n 0)
      (setq found nil pos nil column (current-column) line (line-number-at-pos))
      (completion--move-to-candidate-end)
      (while (and (not found)
                  (eq (forward-line 1) 0)
                  (not (eobp))
                  (move-to-column column))
        (when (get-text-property (point) 'mouse-face)
          (setq found t)))
      (when (not found)
        (if (not completion-auto-wrap)
            (last-completion)
          (save-excursion
            (goto-char (point-min))
            (when (and (eq (move-to-column column) column)
                       (get-text-property (point) 'mouse-face))
              (setq pos (point)))
            (while (and (not pos) (> line (line-number-at-pos)))
              (forward-line 1)
              (when (and (eq (move-to-column column) column)
                         (get-text-property (point) 'mouse-face))
                (setq pos (point)))))
          (if pos (goto-char pos))))
      (setq n (1- n)))

    (while (< n 0)
      (setq found nil pos nil column (current-column) line (line-number-at-pos))
      (completion--move-to-candidate-start)
      (while (and (not found)
                  (eq (forward-line -1) 0)
                  (move-to-column column))
        (when (get-text-property (point) 'mouse-face)
          (setq found t)))
      (when (not found)
        (if (not completion-auto-wrap)
            (first-completion)
          (save-excursion
            (goto-char (point-max))
            (when (and (eq (move-to-column column) column)
                       (get-text-property (point) 'mouse-face))
              (setq pos (point)))
            (while (and (not pos) (< line (line-number-at-pos)))
              (forward-line -1)
              (when (and (eq (move-to-column column) column)
                         (get-text-property (point) 'mouse-face))
                (setq pos (point)))))
          (if pos (goto-char pos))))
      (setq n (1+ n)))))