- (setq ecomplete-current-matches (buffer-string)
- ecomplete-current-line 0
- ecomplete-match-length (count-lines (point-min) (point-max)))
- (ecomplete-highlight-match-line)))))
-
-(defun ecomplete-up-list ()
- "Go up the list of matches."
- (interactive)
- (when (and ecomplete-current-matches
- (> ecomplete-current-line 0))
- (decf ecomplete-current-line)
- (ecomplete-highlight-match-line)))
-
-(defun ecomplete-down-list ()
- "Go down the list of matches."
- (interactive)
- (when (and ecomplete-current-matches
- (< ecomplete-current-line ecomplete-match-length))
- (incf ecomplete-current-line)
- (ecomplete-highlight-match-line)))
-
-(defun ecomplete-highlight-match-line ()
+ (buffer-string)))))
+
+(defun ecomplete-display-matches (type word &optional choose)
+ (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))
+ selected)
+ (define-key local-map (kbd "RET")
+ (lambda () (setq selected (nth line (split-string matches "\n")))))
+ (define-key local-map (kbd "M-n")
+ (lambda () (setq line (min (1+ line) max-lines))))
+ (define-key local-map (kbd "M-p")
+ (lambda () (setq line (max (1- line) 0))))
+ (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))))
+ (if selected
+ (message selected)
+ (message "Abort"))
+ selected)))))
+
+(defun ecomplete-highlight-match-line (matches line)