Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Simplify determining cancel keys by subtracting alpha_buffer_keys fro…

…m default cancel keys.

I hope this change will make the keyboard mappings more robust since it
can no longer miss unmapping keys.
  • Loading branch information...
commit 6118864a4d84521028e8079317f838cef1c32869 1 parent 861b5d5
Lennaert Meijvogel authored lmeijvogel committed
Showing with 166 additions and 200 deletions.
  1. +83 −100 plugin/lusty-juggler.vim
  2. +83 −100 src/lusty/juggler.rb
View
183 plugin/lusty-juggler.vim
@@ -572,23 +572,11 @@ end
module LustyJ
-class LustyJuggler
+class BaseLustyJuggler
public
def initialize
@running = false
@last_pressed = nil
- alpha_buffer_keys = [
- "a",
- "s",
- "d",
- "f",
- "g",
- "h",
- "j",
- "k",
- "l",
- ";",
- ]
@name_bar = NameBar.new(alpha_buffer_keys)
@ALPHA_BUFFER_KEYS = Hash.new
alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
@@ -622,24 +610,10 @@ class LustyJuggler
"<Right>" => "Right",
}
@KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS = [
- "i",
- "I",
- "A",
- "c",
- "C",
- "o",
- "O",
- "S",
- "r",
- "R",
- "q",
- "<Esc>",
- "<C-c>",
- "<BS>",
- "<Del>",
- "<C-h>",
- ]
+ end
+
+ def cancel_mappings
+ @cancel_mappings ||= (default_cancel_mappings - alpha_buffer_keys)
end
def run
@@ -676,7 +650,7 @@ class LustyJuggler
end
# Cancel keys.
- @CANCEL_MAPPINGS.each do |c|
+ cancel_mappings.each do |c|
map_key(c, ":call <SID>LustyJugglerCancel()<CR>")
end
@@ -721,7 +695,7 @@ class LustyJuggler
@KEYPRESS_MAPPINGS.keys.each do |c|
unmap_key(c)
end
- @CANCEL_MAPPINGS.each do |c|
+ cancel_mappings.each do |c|
unmap_key(c)
end
@@ -803,63 +777,88 @@ class LustyJuggler
end
end
end
-end
-class LustyJugglerDvorak < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
- "a",
- "o",
- "e",
- "u",
+ def default_cancel_mappings
+ [
"i",
- "d",
- "h",
- "t",
- "n",
- "s",
+ "I",
+ "A",
+ "c",
+ "C",
+ "o",
+ "O",
+ "S",
+ "r",
+ "R",
+ "q",
+ "<Esc>",
+ "<C-c>",
+ "<BS>",
+ "<Del>",
+ "<C-h>"
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- ["i", "o"].each do |old_cancel_key| @CANCEL_MAPPINGS.delete(old_cancel_key) end
end
-end
+ end
-class LustyJugglerColemak < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ class LustyJuggler < BaseLustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"a",
- "r",
"s",
- "t",
"d",
+ "f",
+ "g",
"h",
- "n",
- "e",
- "i",
- "o",
+ "j",
+ "k",
+ "l",
+ ";",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- ["r", "i", "o"].each do |old_cancel_key| @CANCEL_MAPPINGS.delete(old_cancel_key) end
end
-end
-class LustyJugglerBepo < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ end
+
+ class LustyJugglerDvorak < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
+ "a",
+ "o",
+ "e",
+ "u",
+ "i",
+ "d",
+ "h",
+ "t",
+ "n",
+ "s"
+ ]
+ end
+ end
+
+ class LustyJugglerColemak < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
+ "a",
+ "r",
+ "s",
+ "t",
+ "d",
+ "h",
+ "n",
+ "e",
+ "i",
+ "o",
+ ]
+ end
+ end
+
+ class LustyJugglerBepo < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"a",
"u",
"i",
@@ -871,21 +870,13 @@ class LustyJugglerBepo < LustyJuggler
"n",
"m",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS.delete("i")
- @CANCEL_MAPPINGS.push("c")
end
-end
+ end
-class LustyJugglerAzerty < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ class LustyJugglerAzerty < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"q",
"s",
"d",
@@ -897,16 +888,8 @@ class LustyJugglerAzerty < LustyJuggler
"m",
"ù",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS.delete("q")
- @CANCEL_MAPPINGS.push("c")
- @CANCEL_MAPPINGS.push("a")
end
-end
+ end
end
# An item (delimiter/separator or buffer name) on the NameBar.
View
183 src/lusty/juggler.rb
@@ -8,23 +8,11 @@
# software.
module LustyM
-class LustyJuggler
+class BaseLustyJuggler
public
def initialize
@running = false
@last_pressed = nil
- alpha_buffer_keys = [
- "a",
- "s",
- "d",
- "f",
- "g",
- "h",
- "j",
- "k",
- "l",
- ";",
- ]
@name_bar = NameBar.new(alpha_buffer_keys)
@ALPHA_BUFFER_KEYS = Hash.new
alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
@@ -58,24 +46,10 @@ def initialize
"<Right>" => "Right",
}
@KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS = [
- "i",
- "I",
- "A",
- "c",
- "C",
- "o",
- "O",
- "S",
- "r",
- "R",
- "q",
- "<Esc>",
- "<C-c>",
- "<BS>",
- "<Del>",
- "<C-h>",
- ]
+ end
+
+ def cancel_mappings
+ @cancel_mappings ||= (default_cancel_mappings - alpha_buffer_keys)
end
def run
@@ -112,7 +86,7 @@ def run
end
# Cancel keys.
- @CANCEL_MAPPINGS.each do |c|
+ cancel_mappings.each do |c|
map_key(c, ":call <SID>LustyJugglerCancel()<CR>")
end
@@ -157,7 +131,7 @@ def cleanup
@KEYPRESS_MAPPINGS.keys.each do |c|
unmap_key(c)
end
- @CANCEL_MAPPINGS.each do |c|
+ cancel_mappings.each do |c|
unmap_key(c)
end
@@ -239,63 +213,88 @@ def unmap_key(key)
end
end
end
-end
-class LustyJugglerDvorak < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
- "a",
- "o",
- "e",
- "u",
+ def default_cancel_mappings
+ [
"i",
- "d",
- "h",
- "t",
- "n",
- "s",
+ "I",
+ "A",
+ "c",
+ "C",
+ "o",
+ "O",
+ "S",
+ "r",
+ "R",
+ "q",
+ "<Esc>",
+ "<C-c>",
+ "<BS>",
+ "<Del>",
+ "<C-h>"
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- ["i", "o"].each do |old_cancel_key| @CANCEL_MAPPINGS.delete(old_cancel_key) end
end
-end
+ end
-class LustyJugglerColemak < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ class LustyJuggler < BaseLustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"a",
- "r",
"s",
- "t",
"d",
+ "f",
+ "g",
"h",
- "n",
- "e",
- "i",
- "o",
+ "j",
+ "k",
+ "l",
+ ";",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- ["r", "i", "o"].each do |old_cancel_key| @CANCEL_MAPPINGS.delete(old_cancel_key) end
end
-end
-class LustyJugglerBepo < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ end
+
+ class LustyJugglerDvorak < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
+ "a",
+ "o",
+ "e",
+ "u",
+ "i",
+ "d",
+ "h",
+ "t",
+ "n",
+ "s"
+ ]
+ end
+ end
+
+ class LustyJugglerColemak < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
+ "a",
+ "r",
+ "s",
+ "t",
+ "d",
+ "h",
+ "n",
+ "e",
+ "i",
+ "o",
+ ]
+ end
+ end
+
+ class LustyJugglerBepo < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"a",
"u",
"i",
@@ -307,21 +306,13 @@ def initialize
"n",
"m",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS.delete("i")
- @CANCEL_MAPPINGS.push("c")
end
-end
+ end
-class LustyJugglerAzerty < LustyJuggler
- public
- def initialize
- super
- alpha_buffer_keys = [
+ class LustyJugglerAzerty < LustyJuggler
+ private
+ def alpha_buffer_keys
+ [
"q",
"s",
"d",
@@ -333,14 +324,6 @@ def initialize
"m",
"ù",
]
- @name_bar = NameBar.new(alpha_buffer_keys)
- @ALPHA_BUFFER_KEYS = Hash.new
- alpha_buffer_keys.each_with_index {|x, i| @ALPHA_BUFFER_KEYS[x] = i + 1}
- @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
- @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
- @CANCEL_MAPPINGS.delete("q")
- @CANCEL_MAPPINGS.push("c")
- @CANCEL_MAPPINGS.push("a")
end
-end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.