Skip to content

Commit

Permalink
Simplify determining cancel keys by subtracting alpha_buffer_keys fro…
Browse files Browse the repository at this point in the history
…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
Lennaert Meijvogel authored and Lennaert Meijvogel committed Mar 26, 2013
1 parent 861b5d5 commit 6118864
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 200 deletions.
183 changes: 83 additions & 100 deletions plugin/lusty-juggler.vim
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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.
Expand Down

0 comments on commit 6118864

Please sign in to comment.