Skip to content
Browse files

Version 1.5

Added support for Dvorak keyboard layout.  Enable it with 'let g:LustyJugglerKeyboardLayout = "dvorak"'. (Chris Lasher)
  • Loading branch information...
1 parent e4432db commit 61f241694a6642f2d327e5a00e74900a7ddf9649 Stephen Bach committed with Feb 25, 2012
Showing with 138 additions and 83 deletions.
  1. +138 −83 plugin/lusty-juggler.vim
View
221 plugin/lusty-juggler.vim
@@ -1,4 +1,4 @@
-" Copyright: Copyright (C) 2008-2011 Stephen Bach
+" Copyright: Copyright (C) 2008-2012 Stephen Bach
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
@@ -12,10 +12,11 @@
" Maintainer: Stephen Bach <this-file@sjbach.com>
" Contributors: Juan Frias, Bartosz Leper, Marco Barberis, Vincent Driessen,
" Martin Wache, Johannes Holzfuß, Adam Rutkowski, Carlo Teubner,
-" lilydjwg, Leonid Shevtsov, Giuseppe Rota, Göran Gustafsson
+" lilydjwg, Leonid Shevtsov, Giuseppe Rota, Göran Gustafsson,
+" Chris Lasher
"
-" Release Date: November 25, 2011
-" Version: 1.4
+" Release Date: February 24, 2012
+" Version: 1.5
"
" Usage:
" <Leader>lj - Opens the buffer juggler.
@@ -32,7 +33,8 @@
" new bar showing the names of currently-opened buffers in
" most-recently-used order.
"
-" The buffers are mapped to these keys:
+" By default, LustyJuggler follows the QWERTY layout, and
+" buffers are mapped to these keys:
"
" 1st|2nd|3rd|4th|5th|6th|7th|8th|9th|10th
" ----------------------------------------
@@ -57,6 +59,19 @@
" To cancel the juggler, press any of "q", "<ESC>", "<C-c",
" "<BS>", "<Del>", or "<C-h>".
"
+" LustyJuggler also supports the Dvorak keyboard layout. To
+" enable this feature, place the following in your .vimrc:
+"
+" let g:LustyJugglerKeyboardLayout = "dvorak"
+"
+" With the layout set to "dvorak", the buffer mapping is as
+" follows:
+"
+" 1st|2nd|3rd|4th|5th|6th|7th|8th|9th|10th
+" ----------------------------------------
+" a o e u i d h t n s
+" 1 2 3 4 5 6 7 8 9 0
+"
" LustyJuggler can act very much like <A-Tab> window switching.
" To enable this mode, add the following line to your .vimrc:
"
@@ -330,12 +345,6 @@ module VIM
s.gsub("'", "''")
end
- def self.filename_escape(s)
- # Escape slashes, open square braces, spaces, sharps, double quotes and
- # percent signs.
- s.gsub(/\\/, '\\\\\\').gsub(/[\[ #"%]/, '\\\\\0')
- end
-
def self.regex_escape(s)
s.gsub(/[\]\[.~"^$\\*]/,'\\\\\0')
end
@@ -393,6 +402,27 @@ else
end
end
+if VIM::exists?("*fnameescape")
+ module VIM
+ def self.filename_escape(s)
+ # Escape slashes, open square braces, spaces, sharps, double
+ # quotes and percent signs, and remove leading ./ for files in
+ # pwd.
+ single_quote_escaped = single_quote_escape(s)
+ evaluate("fnameescape('#{single_quote_escaped}')").sub(/^\.\//,"")
+ end
+ end
+else
+ module VIM
+ def self.filename_escape(s)
+ # Escape slashes, open square braces, spaces, sharps, double
+ # quotes and percent signs, and remove leading ./ for files in
+ # pwd.
+ s.gsub(/\\/, '\\\\\\').gsub(/[\[ #"%]/, '\\\\\0').sub(/^\.\//,"")
+ end
+ end
+end
+
# Utility functions.
module LustyJ
@@ -510,33 +540,63 @@ end
module LustyJ
class LustyJuggler
- private
- @@KEYS = { "a" => 1,
- "s" => 2,
- "d" => 3,
- "f" => 4,
- "g" => 5,
- "h" => 6,
- "j" => 7,
- "k" => 8,
- "l" => 9,
- ";" => 10,
- "1" => 1,
- "2" => 2,
- "3" => 3,
- "4" => 4,
- "5" => 5,
- "6" => 6,
- "7" => 7,
- "8" => 8,
- "9" => 9,
- "0" => 10 }
-
public
def initialize
@running = false
@last_pressed = nil
- @name_bar = NameBar.new
+ 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}
+ @NUMERIC_BUFFER_KEYS = {
+ "1" => 1,
+ "2" => 2,
+ "3" => 3,
+ "4" => 4,
+ "5" => 5,
+ "6" => 6,
+ "7" => 7,
+ "8" => 8,
+ "9" => 9,
+ "0" => 10
+ }
+ @BUFFER_KEYS = @ALPHA_BUFFER_KEYS.merge(@NUMERIC_BUFFER_KEYS)
+ @KEYPRESS_KEYS = {
+ # Can't use '<CR>' as an argument to :call func for some reason.
+ "<CR>" => "ENTER",
+ "<Tab>" => "TAB",
+
+ # Split opener keys
+ "v" => "v",
+ "b" => "b",
+
+ # Left and Right keys
+ "<Esc>OD" => "Left",
+ "<Esc>OC" => "Right",
+ "<Left>" => "Left",
+ "<Right>" => "Right",
+ }
+ @KEYPRESS_MAPPINGS = @BUFFER_KEYS.merge(@KEYPRESS_KEYS)
+ @CANCEL_MAPPINGS = [
+ "i",
+ "q",
+ "<Esc>",
+ "<C-c>",
+ "<BS>",
+ "<Del>",
+ "<C-h>",
+ ]
end
def run
@@ -568,31 +628,14 @@ class LustyJuggler
@key_mappings_map = Hash.new { |hash, k| hash[k] = [] }
# Selection keys.
- @@KEYS.keys.each do |c|
+ @KEYPRESS_MAPPINGS.keys.each do |c|
map_key(c, ":call <SID>LustyJugglerKeyPressed('#{c}')<CR>")
end
- # Can't use '<CR>' as an argument to :call func for some reason.
- map_key("<CR>", ":call <SID>LustyJugglerKeyPressed('ENTER')<CR>")
- map_key("<Tab>", ":call <SID>LustyJugglerKeyPressed('TAB')<CR>")
-
- # Split opener keys
- map_key("v", ":call <SID>LustyJugglerKeyPressed('v')<CR>")
- map_key("b", ":call <SID>LustyJugglerKeyPressed('b')<CR>")
-
- # Left and Right keys
- map_key("<Esc>OD", ":call <SID>LustyJugglerKeyPressed('Left')<CR>")
- map_key("<Esc>OC", ":call <SID>LustyJugglerKeyPressed('Right')<CR>")
- map_key("<Left>", ":call <SID>LustyJugglerKeyPressed('Left')<CR>")
- map_key("<Right>", ":call <SID>LustyJugglerKeyPressed('Right')<CR>")
# Cancel keys.
- map_key("i", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("q", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("<Esc>", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("<C-c>", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("<BS>", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("<Del>", ":call <SID>LustyJugglerCancel()<CR>")
- map_key("<C-h>", ":call <SID>LustyJugglerCancel()<CR>")
+ @CANCEL_MAPPINGS.each do |c|
+ map_key(c, ":call <SID>LustyJugglerCancel()<CR>")
+ end
@last_pressed = 2 if LustyJuggler::alt_tab_mode_active?
print_buffer_list(@last_pressed)
@@ -603,7 +646,7 @@ class LustyJuggler
if @last_pressed.nil? and c == 'ENTER'
cleanup()
- elsif @last_pressed and (@@KEYS[c] == @last_pressed or c == 'ENTER')
+ elsif @last_pressed and (@BUFFER_KEYS[c] == @last_pressed or c == 'ENTER')
choose(@last_pressed)
cleanup()
elsif @last_pressed and %w(v b).include?(c)
@@ -618,7 +661,7 @@ class LustyJuggler
@last_pressed = (@last_pressed + 1) > $lj_buffer_stack.length ? 1 : (@last_pressed + 1)
print_buffer_list(@last_pressed)
else
- @last_pressed = @@KEYS[c]
+ @last_pressed = @BUFFER_KEYS[c]
print_buffer_list(@last_pressed)
end
end
@@ -632,26 +675,12 @@ class LustyJuggler
VIM::set_option "showcmd" if @showcmd
VIM::set_option "showmode" if @showmode
- @@KEYS.keys.each do |c|
+ @KEYPRESS_MAPPINGS.keys.each do |c|
+ unmap_key(c)
+ end
+ @CANCEL_MAPPINGS.each do |c|
unmap_key(c)
end
- unmap_key("<CR>")
- unmap_key("<Tab>")
-
- unmap_key("v")
- unmap_key("b")
-
- unmap_key("i")
- unmap_key("q")
- unmap_key("<Esc>")
- unmap_key("<C-c>")
- unmap_key("<BS>")
- unmap_key("<Del>")
- unmap_key("<C-h>")
- unmap_key("<Esc>OC")
- unmap_key("<Esc>OD")
- unmap_key("<Left>")
- unmap_key("<Right>")
@running = false
VIM::message ''
@@ -732,8 +761,33 @@ class LustyJuggler
end
end
end
-end
+class LustyJugglerDvorak < LustyJuggler
+ public
+ def initialize
+ super
+ alpha_buffer_keys = [
+ "a",
+ "o",
+ "e",
+ "u",
+ "i",
+ "d",
+ "h",
+ "t",
+ "n",
+ "s",
+ ]
+ @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
# An item (delimiter/separator or buffer name) on the NameBar.
module LustyJ
@@ -864,8 +918,9 @@ end
module LustyJ
class NameBar
public
- def initialize
+ def initialize(letters)
@selected_buffer = nil
+ @LETTERS = letters
end
attr_writer :selected_buffer
@@ -883,9 +938,6 @@ class NameBar
NameBar.do_pretty_print(clipped)
end
- private
- @@LETTERS = ["a", "s", "d", "f", "g", "h", "j", "k", "l", ";"]
-
def create_items
names = $lj_buffer_stack.names(10)
@@ -894,7 +946,7 @@ class NameBar
key = if VIM::exists?("g:LustyJugglerShowKeys")
case VIM::evaluate("g:LustyJugglerShowKeys").to_s
when /[[:alpha:]]/
- @@LETTERS[array.size / 2] + ":"
+ @LETTERS[array.size / 2] + ":"
when /[[:digit:]]/
"#{((array.size / 2) + 1) % 10}:"
else
@@ -1034,7 +1086,6 @@ end
end
-
# Maintain MRU ordering.
module LustyJ
class BufferStack
@@ -1144,7 +1195,11 @@ end
-$lusty_juggler = LustyJ::LustyJuggler.new
+if VIM::exists?('g:LustyJugglerKeyboardLayout') and VIM::evaluate_bool('g:LustyJugglerKeyboardLayout == "dvorak"')
+ $lusty_juggler = LustyJ::LustyJugglerDvorak.new
+else
+ $lusty_juggler = LustyJ::LustyJuggler.new
+end
$lj_buffer_stack = LustyJ::BufferStack.new
EOF

0 comments on commit 61f2416

Please sign in to comment.
Something went wrong with that request. Please try again.