Function: ecomplete-display-matches

ecomplete-display-matches is a byte-compiled function defined in ecomplete.el.gz.

Signature

(ecomplete-display-matches TYPE WORD &optional CHOOSE)

Documentation

Display the top-rated elements TYPE that match WORD.

If CHOOSE, allow the user to choose interactively between the matches.

Auto-select when ecomplete-auto-select is non-nil and there is only a single completion option available.

Source Code

;; Defined in /usr/src/emacs/lisp/ecomplete.el.gz
(defun ecomplete-display-matches (type word &optional choose)
  "Display the top-rated elements TYPE that match WORD.
If CHOOSE, allow the user to choose interactively between the
matches.

Auto-select when `ecomplete-auto-select' is
non-nil and there is only a single completion option available."
  (let* ((matches (ecomplete-get-matches type word))
         (match-list (and matches (split-string matches "\n")))
         (max-lines (and matches (- (length match-list) 2)))
	 (line 0)
	 (message-log-max nil)
	 command highlight)
    (if (not matches)
	(progn
	  (message "No ecomplete matches")
	  nil)
      (if (not choose)
	  (progn
	    (message "%s" matches)
	    nil)
        (if (and ecomplete-auto-select
                 max-lines
                 (zerop max-lines))
            ;; Auto-select when only one option is available.
            (nth 0 match-list)
          ;; Interactively choose from the filtered completions.
	  (let ((local-map (make-sparse-keymap))
                (prev-func (lambda () (setq line (max (1- line) 0))))
                (next-func (lambda () (setq line (min (1+ line) max-lines))))
                selected)
	    (define-key local-map (kbd "RET")
                        (lambda () (setq selected (nth line match-list))))
	    (define-key local-map (kbd "M-n") next-func)
	    (define-key local-map (kbd "<down>") next-func)
	    (define-key local-map (kbd "M-p") prev-func)
	    (define-key local-map (kbd "<up>") prev-func)
	    (let ((overriding-local-map local-map))
              (setq highlight (ecomplete-highlight-match-line matches line))
	      (while (and (null selected)
			  (setq command (read-key-sequence highlight))
			  (lookup-key local-map command))
                (apply (key-binding command) nil)
                (setq highlight (ecomplete-highlight-match-line matches line))))
	    (message (or selected "Abort"))
            selected))))))