Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] ecomplete.el: Use a local keymap to handle bindings
@ 2011-09-22 13:37 Kan-Ru Chen
  2011-09-26 15:14 ` Julien Danjou
  2011-09-26 19:03 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 8+ messages in thread
From: Kan-Ru Chen @ 2011-09-22 13:37 UTC (permalink / raw)
  To: ding; +Cc: Lars Magne Ingebrigtsen, Julien Danjou, Kan-Ru Chen

---
 lisp/ChangeLog    |    5 +++++
 lisp/ecomplete.el |   27 ++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1984ead..c89cb59 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -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-21  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
 	* message.el (message-indent-citation): Really make sure there's a
diff --git a/lisp/ecomplete.el b/lisp/ecomplete.el
index 6a47b11..08b7323 100644
--- a/lisp/ecomplete.el
+++ b/lisp/ecomplete.el
@@ -123,15 +123,24 @@
 	    (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
-- 
1.7.6.3




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-10-06 21:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-22 13:37 [PATCH] ecomplete.el: Use a local keymap to handle bindings Kan-Ru Chen
2011-09-26 15:14 ` Julien Danjou
2011-09-26 17:59   ` Kan-Ru Chen
2011-09-26 19:03 ` Lars Magne Ingebrigtsen
2011-09-26 21:00   ` Lars Magne Ingebrigtsen
2011-09-27  5:08     ` Kan-Ru Chen
2011-09-27  5:09       ` [PATCHv3] " Kan-Ru Chen
2011-10-06 21:33       ` [PATCH] " Lars Magne Ingebrigtsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).