* ecomplete.el (ecomplete-display-matches): Use a local keymap to
authorKan-Ru Chen <kanru@kanru.info>
Mon, 26 Sep 2011 19:03:02 +0000 (21:03 +0200)
committerLars Magne Ingebrigtsen <larsi@stories.gnus.org>
Mon, 26 Sep 2011 19:03:02 +0000 (21:03 +0200)
handle bindings.

lisp/ChangeLog
lisp/ecomplete.el

index 72641de..67a09ae 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-22  Kan-Ru Chen  <kanru@kanru.info>
+
+       * ecomplete.el (ecomplete-display-matches): Use a local keymap to
+       handle bindings.
+
 2011-09-26  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * pop3.el (pop3-number-of-responses): Removed.
index 6a47b11..08b7323 100644 (file)
            (message "%s" matches)
            nil)
        (setq highlight (ecomplete-highlight-match-line matches line))
-       (while (not (memq (setq command (read-event highlight)) '(? return)))
-         (cond
-          ((eq command ?\M-n)
-           (setq line (min (1+ line) max-lines)))
-          ((eq command ?\M-p)
-           (setq line (max (1- line) 0))))
-         (setq highlight (ecomplete-highlight-match-line matches line)))
-       (when (eq command 'return)
-         (nth line (split-string matches "\n")))))))
+       (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)
   (with-temp-buffer