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). In vertical format (see user option completions-format) this command moves line-wise through all columns in the completions buffer, in horizontal format movement is confined to the current column of completions.

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).  In vertical format (see user option `completions-format')
this command moves line-wise through all columns in the completions
buffer, in horizontal format movement is confined to the current column
of completions.

Also see the `completion-auto-wrap' variable."
  (interactive "p")
  (let ((tabcommand (member (this-command-keys) '("\t" [backtab])))
        line column pos found last first)
    (catch 'bound
      (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 (point) column (current-column)
            line (line-number-at-pos)
            last (= (point) (save-excursion (last-completion) (point))))
      (if (and (eq completions-format 'vertical)
               completion-auto-wrap last)
          (if (and (eq completion-auto-select t) tabcommand
                   (minibufferp completion-reference-buffer))
              (progn
                (completions--clear-selection)
                (throw 'bound nil))     ; Skip to minibuffer.
            (first-completion))         ; Wrap from last to first item.
        (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 (and (not completion-auto-wrap)
                   (if (eq completions-format 'vertical)
                       (and (or last (get-text-property (point) 'mouse-face))
                            (last-completion))
                     (goto-char pos)))
              t
            (save-excursion
              (setq pos nil)
              (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))
            (when (eq completions-format 'vertical)
              (next-column-completion 1)))))   ; Move to next column.
      (setq n (1- n)))

    (while (< n 0)
      (setq found nil pos (point) column (current-column)
            line (line-number-at-pos)
            first (= (point) (save-excursion (first-completion) (point))))
      (if (and (eq completions-format 'vertical)
               completion-auto-wrap first)
          (if (and (eq completion-auto-select t) tabcommand
                   (minibufferp completion-reference-buffer))
              (progn
                (completions--clear-selection)
                (throw 'bound nil))     ; Skip to minibuffer.
            (last-completion))          ; Wrap from first to last item.
        (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 (and (not completion-auto-wrap)
                   (if (eq completions-format 'vertical)
                       (and (or last first
                                (get-text-property (point) 'mouse-face))
                            first (first-completion))
                     (goto-char pos)))
              t
            (save-excursion
              (setq pos nil)
              (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))
            (when (eq completions-format 'vertical)
              (previous-column-completion 1)   ; Move to previous column.
              (setq column (current-column))
              ;; Move to last item in this column (previous column may
              ;; have fewer items).
              (while (not (eobp))
                (move-to-column column)
                (setq pos (point))
                (forward-line))
              (goto-char pos)))))
      (setq n (1+ n))))

    (when (/= 0 n)
      (switch-to-minibuffer))))