Gnus development mailing list
 help / color / mirror / Atom feed
From: Kan-Ru Chen <kanru@kanru.info>
To: ding@gnus.org
Cc: Lars Magne Ingebrigtsen <larsi@gnus.org>, Kan-Ru Chen <kanru@kanru.info>
Subject: [PATCHv3] ecomplete.el: Use a local keymap to handle bindings
Date: Tue, 27 Sep 2011 13:09:07 +0800	[thread overview]
Message-ID: <1317100147-24700-1-git-send-email-kanru@kanru.info> (raw)
In-Reply-To: <8762kewp1f.fsf@isil.kanru.info>

---
 lisp/ChangeLog    |    5 +++++
 lisp/ecomplete.el |   32 +++++++++++++++++++++++---------
 2 files changed, 28 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..5d1c46b 100644
--- a/lisp/ecomplete.el
+++ b/lisp/ecomplete.el
@@ -27,6 +27,11 @@
 (eval-when-compile
   (require 'cl))
 
+(eval-when-compile
+  (when (featurep 'xemacs)
+    ;; The `kbd' macro requires that the `read-kbd-macro' macro is available.
+    (require 'edmacro)))
+
 (defgroup ecomplete nil
   "Electric completion of email addresses and the like."
   :group 'mail)
@@ -123,15 +128,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




  reply	other threads:[~2011-09-27  5:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-22 13:37 [PATCH] " 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       ` Kan-Ru Chen [this message]
2011-10-06 21:33       ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1317100147-24700-1-git-send-email-kanru@kanru.info \
    --to=kanru@kanru.info \
    --cc=ding@gnus.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).