Function: next-column-completion

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

Signature

(next-column-completion N)

Documentation

Move to the item in the next column of the completions buffer.

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

Also see the completion-auto-wrap variable.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun next-column-completion (n)
  "Move to the item in the next column of the completions buffer.
With prefix argument N, move N columns (negative N means move
backward).

Also see the `completion-auto-wrap' variable."
  (interactive "p")
  (let ((tabcommand (member (this-command-keys) '("\t" [backtab])))
        (one-col (save-excursion
                   (first-completion)
                   (completion--move-to-candidate-end)
                   (eolp)))
        pos line 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)))

      (while (> n 0)
        (setq pos (point) line (line-number-at-pos)
              last (if one-col
                       (save-excursion (and (forward-line) (eobp)))
                     (save-excursion (completion--move-to-candidate-end) (eolp))))
        ;; If in a completion, move to the end of it.
        (when (get-text-property pos 'mouse-face)
          (setq pos (next-single-property-change pos 'mouse-face)))
        (when pos (setq pos (next-single-property-change pos 'mouse-face)))
        (if (and pos
                 (if last
                     (not (eq completions-format 'vertical))
                   t))
            ;; Move to the start of next one.
            (goto-char pos)
          ;; If at the last completion option, wrap or skip
          ;; to the minibuffer, if requested.
          (when (and completion-auto-wrap
                     (or one-col
                         (not (eq completions-format 'vertical))))
            (if (and (eq completion-auto-select t) tabcommand
                     (minibufferp completion-reference-buffer))
                (throw 'bound nil)
              (first-completion))))
        (when (and (eq completions-format 'vertical)
                   (or last
                       (= (point) (save-excursion (first-completion) (point)))))
          (if (> (line-number-at-pos) line)
              (forward-line -1)
            (when completion-auto-wrap
              (goto-char (pos-bol))
              (completion--move-to-candidate-start))))
        (setq n (1- n)))

      (while (< n 0)
        (setq pos (point) line (line-number-at-pos)
              first (if one-col
                        (save-excursion
                          (forward-line -1)
                          (not (get-text-property (point) 'mouse-face)))
                      (save-excursion (completion--move-to-candidate-start)
                                      (bolp))))
        ;; If in a completion, move to the start of it.
        (when (and (get-text-property pos 'mouse-face)
                   (not (bobp))
                   (get-text-property (1- pos) 'mouse-face))
          (setq pos (previous-single-property-change pos 'mouse-face)))
        (when pos (setq pos (previous-single-property-change pos 'mouse-face)))
        (if (and pos
                 (not (and completion-auto-wrap
                           (eq completions-format 'vertical)
                           (not one-col)
                           (bolp)))
                 (if first
                     (not (eq completions-format 'vertical))
                   t))
            (progn
              (goto-char pos)
              ;; Move to the start of that one.
              (unless (get-text-property (point) 'mouse-face)
                (goto-char (previous-single-property-change
                            (point) 'mouse-face nil (point-min)))))
          ;; If at the first completion option, wrap or skip
          ;; to the minibuffer, if requested.
          (when completion-auto-wrap
            (cond ((and (eq completions-format 'vertical)
                        (not one-col)
                        (or first (not pos)))
                   (when (> line (line-number-at-pos))
                     (forward-line))
                   (goto-char (1- (pos-eol)))
                   (completion--move-to-candidate-start))
                  ((and (eq completion-auto-select t) tabcommand
                        (minibufferp completion-reference-buffer))
                   (progn
                     (throw 'bound nil)))
                  (t
                   (last-completion)))))
        (setq n (1+ n))))

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