From: Kan-Ru Chen <kanru@kanru.info>
To: ding@gnus.org
Cc: Lars Magne Ingebrigtsen <larsi@gnus.org>,
Julien Danjou <julien@danjou.info>,
Kan-Ru Chen <kanru@kanru.info>
Subject: [PATCH] ecomplete.el: Use a local keymap to handle bindings
Date: Thu, 22 Sep 2011 21:37:06 +0800 [thread overview]
Message-ID: <1316698626-6525-1-git-send-email-kanru@kanru.info> (raw)
---
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
next reply other threads:[~2011-09-22 13:37 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-22 13:37 Kan-Ru Chen [this message]
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
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=1316698626-6525-1-git-send-email-kanru@kanru.info \
--to=kanru@kanru.info \
--cc=ding@gnus.org \
--cc=julien@danjou.info \
--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).