From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.28.69 with SMTP id l5cs51429ebc; Sun, 24 Jan 2010 19:10:51 -0800 (PST) Received: by 10.224.41.134 with SMTP id o6mr3791373qae.152.1264389051088; Sun, 24 Jan 2010 19:10:51 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 5si16331312qwg.38.2010.01.24.19.10.50; Sun, 24 Jan 2010 19:10:51 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 2A2CD167830E; Sun, 24 Jan 2010 22:10:50 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 9FCEB185830B for ; Sun, 24 Jan 2010 22:10:47 -0500 (EST) Received: (qmail 10551 invoked from network); 25 Jan 2010 03:10:47 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 25 Jan 2010 03:10:47 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Sun, 24 Jan 2010 19:09:32 -0800 Message-Id: <1264388973-5804-2-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1264388973-5804-1-git-send-email-rlane@club.cc.cmu.edu> References: <1264388973-5804-1-git-send-email-rlane@club.cc.cmu.edu> Subject: [sup-devel] [PATCH 2/3] add keymap rebinding support X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org Keymap#delete removes an existing keybinding and Keymap#add! deletes existing bindings to the given keys before adding new ones. Keymap#add_multi now allows adding new bindings to an existing submap. --- lib/sup/keymap.rb | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/sup/keymap.rb b/lib/sup/keymap.rb index cb039e4..4cdeeed 100644 --- a/lib/sup/keymap.rb +++ b/lib/sup/keymap.rb @@ -60,10 +60,31 @@ class Keymap end end + def delete k + kc = Keymap.keysym_to_keycode(k) + return unless @map.member? kc + entry = @map.delete kc + keys = entry[2] + keys.delete k + @order.delete entry if keys.empty? + end + + def add! action, help, *keys + keys.each { |k| delete k } + add action, help, *keys + end + def add_multi prompt, key - submap = Keymap.new - add submap, prompt, key - yield submap + kc = Keymap.keysym_to_keycode(key) + if @map.member? kc + action = @map[kc].first + raise "existing action is not a keymap" unless action.is_a?(Keymap) + yield action + else + submap = Keymap.new + add submap, prompt, key + yield submap + end end def action_for kc -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel