From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/80062 Path: news.gmane.org!not-for-mail From: Kan-Ru Chen Newsgroups: gmane.emacs.gnus.general Subject: [PATCHv3] ecomplete.el: Use a local keymap to handle bindings Date: Tue, 27 Sep 2011 13:09:07 +0800 Message-ID: <1317100147-24700-1-git-send-email-kanru@kanru.info> References: <8762kewp1f.fsf@isil.kanru.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1317100226 11247 80.91.229.12 (27 Sep 2011 05:10:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 27 Sep 2011 05:10:26 +0000 (UTC) Cc: Lars Magne Ingebrigtsen , Kan-Ru Chen To: ding@gnus.org Original-X-From: ding-owner+M28357@lists.math.uh.edu Tue Sep 27 07:10:22 2011 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R8Pvw-0007Kq-Jz for ding-account@gmane.org; Tue, 27 Sep 2011 07:10:20 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1R8PvY-000829-CV; Tue, 27 Sep 2011 00:09:56 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1R8PvX-00081v-2W for ding@lists.math.uh.edu; Tue, 27 Sep 2011 00:09:55 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1R8PvS-0002Xn-Sy for ding@lists.math.uh.edu; Tue, 27 Sep 2011 00:09:54 -0500 Original-Received: from mail-yx0-f172.google.com ([209.85.213.172]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1R8PvR-0003KX-CM; Tue, 27 Sep 2011 07:09:49 +0200 Original-Received: by yxt33 with SMTP id 33so7546941yxt.17 for ; Mon, 26 Sep 2011 22:09:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=p68zMzcXfY0kyoTeEPWng1GIQTI2CArYLcDNJ+qZPWE=; b=le7QU5eET04P23QU4S/8gUEscKpsMHQ/ZXsHoUJ4L8kEGqwW/CRz2httEyb9c/VVg1 EUVJoHzrqdce61wC3Dk6Z/qF5lRYDW1ZKe0ecyxynjxZfLsFSnPKYn1SRD5aVL7g/CZ9 5ZL4N6zVRJZE0FMVW+dff+H96i0bPMLeqzcX4= Original-Received: by 10.236.177.66 with SMTP id c42mr44657062yhm.14.1317100183370; Mon, 26 Sep 2011 22:09:43 -0700 (PDT) Original-Received: from isil.kanru.info (61-30-10-70.static.tfn.net.tw. [61.30.10.70]) by mx.google.com with ESMTPS id v28sm32235163yhi.11.2011.09.26.22.09.37 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 26 Sep 2011 22:09:42 -0700 (PDT) Original-Received: from kanru by isil.kanru.info with local (Exim 4.76) (envelope-from ) id 1R8PvB-0006Rk-9f; Tue, 27 Sep 2011 13:09:33 +0800 X-Mailer: git-send-email 1.7.6.3 In-Reply-To: <8762kewp1f.fsf@isil.kanru.info> X-Spam-Score: -2.9 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:80062 Archived-At: --- 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 + + * ecomplete.el (ecomplete-display-matches): Use a local keymap to + handle bindings. + 2011-09-21 Lars Magne Ingebrigtsen * 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