Function: completion--in-region-1

completion--in-region-1 is a byte-compiled function defined in minibuffer.el.gz.

Signature

(completion--in-region-1 BEG END)

Source Code

;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(defun completion--in-region-1 (beg end)
  ;; If the previous command was not this,
  ;; mark the completion buffer obsolete.
  (setq this-command 'completion-at-point)
  (unless (eq 'completion-at-point last-command)
    (completion--flush-all-sorted-completions)
    (setq minibuffer-scroll-window nil))

  (cond
   ;; If there's a fresh completion window with a live buffer,
   ;; and this command is repeated, scroll that window.
   ((and (window-live-p minibuffer-scroll-window)
         (eq t (frame-visible-p (window-frame minibuffer-scroll-window))))
    (let ((window minibuffer-scroll-window))
      (with-current-buffer (window-buffer window)
        (cond
         ;; Here this is possible only when second-tab, but instead of
         ;; scrolling the completion list window, switch to it below,
         ;; outside of `with-current-buffer'.
         ((eq completion-auto-select 'second-tab))
         ;; Reverse tab
         ((equal (this-command-keys) [backtab])
          (if (pos-visible-in-window-p (point-min) window)
              ;; If beginning is in view, scroll up to the end.
              (set-window-point window (point-max))
            ;; Else scroll down one screen.
            (with-selected-window window (scroll-down))))
         ;; Normal tab
         (t
          (if (pos-visible-in-window-p (point-max) window)
              ;; If end is in view, scroll up to the end.
              (set-window-start window (point-min) nil)
            ;; Else scroll down one screen.
            (with-selected-window window (scroll-up))))))
      (when (eq completion-auto-select 'second-tab)
        (switch-to-completions))
      nil))
   ;; If we're cycling, keep on cycling.
   ((and completion-cycling completion-all-sorted-completions)
    (minibuffer-force-complete beg end)
    t)
   (t (prog1 (pcase (completion--do-completion beg end)
               (#b000 nil)
               (_     t))
        (if (window-live-p minibuffer-scroll-window)
            (and (eq completion-auto-select t)
                 (eq t (frame-visible-p (window-frame minibuffer-scroll-window)))
                 ;; When the completion list window was displayed, select it.
                 (switch-to-completions))
          (completion-in-region-mode -1))))))