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.

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."
  (let* ((matches (ecomplete-get-matches type word))
	 (line 0)
	 (max-lines (when matches (- (length (split-string matches "\n")) 2)))
	 (message-log-max nil)
	 command highlight)
    (if (not matches)
	(progn
	  (message "No ecomplete matches")
	  nil)
      (if (not choose)
	  (progn
	    (message "%s" matches)
	    nil)
	(setq highlight (ecomplete-highlight-match-line matches line))
	(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 (split-string matches "\n")))))
	  (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))
	    (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)))))