Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Rich Lane <rlane@club.cc.cmu.edu>
To: sup-devel@rubyforge.org
Subject: [sup-devel] [PATCH 2/3] add keymap rebinding support
Date: Sun, 24 Jan 2010 19:09:32 -0800	[thread overview]
Message-ID: <1264388973-5804-2-git-send-email-rlane@club.cc.cmu.edu> (raw)
In-Reply-To: <1264388973-5804-1-git-send-email-rlane@club.cc.cmu.edu>

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


  reply	other threads:[~2010-01-25  3:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-25  3:09 [sup-devel] [PATCH 1/3] make mode keymap easily accessible to hooks Rich Lane
2010-01-25  3:09 ` Rich Lane [this message]
2010-01-25  3:09   ` [sup-devel] [PATCH 3/3] keybindings hook Rich Lane
2010-02-27  7:34     ` Rich Lane

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=1264388973-5804-2-git-send-email-rlane@club.cc.cmu.edu \
    --to=rlane@club.cc.cmu.edu \
    --cc=sup-devel@rubyforge.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