Disable yankring, update lusty, add italics

git-svn-id: http://photonzero.com/dotfiles/trunk@93 23f722f6-122a-0410-8cef-c75bd312dd78
This commit is contained in:
michener 2011-04-12 23:58:58 +00:00
parent 505e3205d2
commit b5f5d230a3
19 changed files with 2795 additions and 2608 deletions

View file

@ -1,2 +1,5 @@
Don't throw an error when looking up special non-file buffers.
New and improved fuzzy matching algorithm.
- New and improved fuzzy matching algorithm: Mercury. (Matt Tolton)
- Buffer Explorer: don't show unlisted buffers. (Thanks to Johannes Holzfuß)
- Align multi-byte CJK characters correctly in filenames. (Thanks to lilydjwg)
- Truncate prompt if longer than window width to avoid "press any key" message. (Thanks to Martin Wache)
- Save/restore window config better. (Thanks to robquant)

View file

@ -1,3 +1,3 @@
- don't error if ENTER is pressed before selection
- avoid a "Press ENTER to continue" message. (Thanks to Bartosz Leper)
- don't error when the QuickFix buffer is open. (Thanks to Marco Barberis)
- Don't show unlisted buffers. (Thanks to Johannes Holzfuß)
- New Alt-Tab mode to emulate window manager switching. See g:LustyJugglerAltTabMode in documentation. (Thanks to Martin Wache)
- Save and restore keymappings. (Thanks to Vincent Driessen)

View file

@ -1,11 +1,11 @@
LustyJuggler is a high speed buffer juggler. Having to consciously think about which buffer you need to switch to sucks, so use this instead.
Here's an animated gif showing it in action:
Someone made a screen cast showing it in action (jump to 6:20):
http://lococast.net/archives/185
Some older stuff:
http://viewglob.sourceforge.net/lusty-juggler-animated.gif
Annotated snapshot progression:
http://viewglob.sourceforge.net/lusty-juggler-annotated.png
Launch the juggler with this key combo:
@ -34,9 +34,12 @@ If you want to switch to that buffer, press "f" or "4" again or press "<ENTER>".
If you changed your mind, cancel the juggler with any of "q", "<ESC>", "<C-c", "<BS>", "<Del>", or "<C-h>".
If you like LustyJuggler, you may also like LustyExplorer: vimscript #1890
Development repository: http://github.com/sjbach/lusty
install details
Copy the script into your $HOME/.vim/plugin directory so that it will be sourced on startup.
NOTE: This plugin requires Vim be compiled with Ruby interpretation. If you do not currently have this functionality, see the "Install Details:" section of the script for directions on adding it. It's not too tough.
Also: because of a bug in Vim's maparg() call, this plugin can interact poorly with plugins that remap common normal mode keys such as "d" (for dd, dw, etc.) and "<ENTER>". These include YankRing and SuperTab.

View file

@ -15,10 +15,10 @@
" Rajendra Badapanda, cho45, Simo Salminen, Sami Samhuri,
" Matt Tolton, Björn Winckler, sowill, David Brown
" Brett DiFrischia, Ali Asad Lotia, Kenneth Love, Ben Boeckel,
" robquant
" robquant, lilydjwg, Martin Wache, Johannes Holzfuß
"
" Release Date: July 21, 2010
" Version: 3.1.1
" Release Date: December 16, 2010
" Version: 4.0
"
" Usage:
" <Leader>lf - Opens the filesystem explorer.
@ -59,6 +59,8 @@
"
" <C-n> select [n]ext match
" <C-p> select [p]revious match
" <C-f> select [f]orward one column
" <C-b> select [b]ack one column
"
" <C-u> clear prompt
"
@ -242,8 +244,8 @@ let g:loaded_lustyexplorer = "yep"
" Commands.
command LustyBufferExplorer :call <SID>LustyBufferExplorerStart()
command LustyFilesystemExplorer :call <SID>LustyFilesystemExplorerStart()
command LustyFilesystemExplorerFromHere :call <SID>LustyFilesystemExplorerFromHereStart()
command -nargs=? LustyFilesystemExplorer :call <SID>LustyFilesystemExplorerStart("<args>")
command LustyFilesystemExplorerFromHere :call <SID>LustyFilesystemExplorerStart(expand("%:p:h"))
command LustyBufferGrep :call <SID>LustyBufferGrepStart()
" Deprecated command names.
@ -269,12 +271,8 @@ nmap <silent> <Leader>lb :LustyBufferExplorer<CR>
nmap <silent> <Leader>lg :LustyBufferGrep<CR>
" Vim-to-ruby function calls.
function! s:LustyFilesystemExplorerStart()
ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_wd }
endfunction
function! s:LustyFilesystemExplorerFromHereStart()
ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_here }
function! s:LustyFilesystemExplorerStart(path)
exec "ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_path('".a:path."') }"
endfunction
function! s:LustyBufferExplorerStart()
@ -410,6 +408,10 @@ module VIM
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&modified')")
end
def listed?
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&buflisted')")
end
def self.obj_for_bufnr(n)
# There's gotta be a better way to do this...
(0..VIM::Buffer.count-1).each do |i|
@ -438,6 +440,22 @@ module VIM
end
end
# Hack for wide CJK characters.
if VIM::exists?("*strwidth")
module VIM
def self.strwidth(s)
# strwidth() is defined in Vim 7.3.
evaluate("strwidth('#{single_quote_escape(s)}')").to_i
end
end
else
module VIM
def self.strwidth(s)
s.length
end
end
end
# Utility functions.
module LustyE
@ -659,12 +677,13 @@ class Entry
@label = label
end
# NOTE: very similar to BufferStack::shorten_paths()
def self.compute_buffer_entries()
buffer_entries = []
$le_buffer_stack.numbers.each do |n|
o = VIM::Buffer.obj_for_bufnr(n)
next if o.nil?
next if (o.nil? or not o.listed?)
buffer_entries << self.new(o, n)
end
@ -804,6 +823,26 @@ class Explorer
@selected_index = \
(@selected_index - 1) % @current_sorted_matches.size
refresh_mode = :no_recompute
when 6 # C-f (select right)
columns = (@current_sorted_matches.size.to_f / @row_count.to_f).ceil
cur_column = @selected_index / @row_count
cur_row = @selected_index % @row_count
new_column = (cur_column + 1) % columns
if (new_column + 1) * (cur_row + 1) > @current_sorted_matches.size
new_column = 0
end
@selected_index = new_column * @row_count + cur_row
refresh_mode = :no_recompute
when 2 # C-b (select left)
columns = (@current_sorted_matches.size.to_f / @row_count.to_f).ceil
cur_column = @selected_index / @row_count
cur_row = @selected_index % @row_count
new_column = (cur_column - 1) % columns
if (new_column + 1) * (cur_row + 1) > @current_sorted_matches.size
new_column = columns - 2
end
@selected_index = new_column * @row_count + cur_row
refresh_mode = :no_recompute
when 15 # C-o choose in new horizontal split
choose(:new_split)
when 20 # C-t choose in new tab
@ -846,8 +885,8 @@ class Explorer
on_refresh()
highlight_selected_index() if VIM::has_syntax?
@display.print @current_sorted_matches.map { |x| x.label }
@prompt.print
@row_count = @display.print @current_sorted_matches.map { |x| x.label }
@prompt.print Display.max_width
end
def create_explorer_window
@ -1032,21 +1071,12 @@ class FilesystemExplorer < Explorer
super
end
def run_from_here
def run_from_path(path)
return if @running
start_path = if $curbuf.name.nil?
VIM::getcwd()
else
VIM::evaluate("expand('%:p:h')")
end
@prompt.set!(start_path + File::SEPARATOR)
run()
end
def run_from_wd
return if @running
@prompt.set!(VIM::getcwd() + File::SEPARATOR)
if path.empty?
path = VIM::getcwd()
end
@prompt.set!(path + File::SEPARATOR)
run()
end
@ -1469,9 +1499,16 @@ class Prompt
@input = ""
end
def print
def print(max_width = 0)
text = @input
# may need some extra characters for "..." and spacing
max_width -= 5
if max_width > 0 && text.length > max_width
text = "..." + text[(text.length - max_width + 3 ) .. -1]
end
VIM::pretty_msg("Comment", @@PROMPT,
"None", VIM::single_quote_escape(@input),
"None", VIM::single_quote_escape(text),
"Underlined", " ")
end
@ -1782,6 +1819,10 @@ class Display
VIM::command 'highlight link LustyFileWithSwap WarningMsg'
VIM::command 'highlight link LustyNoEntries ErrorMsg'
VIM::command 'highlight link LustyTruncated Visual'
if VIM::exists? '*clearmatches'
VIM::evaluate 'clearmatches()'
end
end
#
@ -1820,6 +1861,8 @@ class Display
VIM::command "#{map} <C-w> :call <SID>#{prefix}KeyPressed(23)<CR>"
VIM::command "#{map} <C-n> :call <SID>#{prefix}KeyPressed(14)<CR>"
VIM::command "#{map} <C-p> :call <SID>#{prefix}KeyPressed(16)<CR>"
VIM::command "#{map} <C-f> :call <SID>#{prefix}KeyPressed(6)<CR>"
VIM::command "#{map} <C-b> :call <SID>#{prefix}KeyPressed(2)<CR>"
VIM::command "#{map} <C-o> :call <SID>#{prefix}KeyPressed(15)<CR>"
VIM::command "#{map} <C-t> :call <SID>#{prefix}KeyPressed(20)<CR>"
VIM::command "#{map} <C-v> :call <SID>#{prefix}KeyPressed(22)<CR>"
@ -1851,7 +1894,7 @@ class Display
if col_index < col_count - 1
# Add spacer to the width of the column
rows[i] << (" " * (column_width - string.length))
rows[i] << (" " * (column_width - VIM::strwidth(string)))
rows[i] << @@COLUMN_SEPARATOR
end
end
@ -1861,6 +1904,7 @@ class Display
end
print_rows(rows, truncated)
row_count
end
def close
@ -1928,7 +1972,8 @@ class Display
column_widths = []
total_width = 0
strings.each_slice(optimal_row_count) do |column|
column_width = column.max { |a, b| a.length <=> b.length }.length
longest = column.max { |a, b| VIM::strwidth(a) <=> VIM::strwidth(b) }
column_width = VIM::strwidth(longest)
total_width += column_width
break if total_width > max_width
@ -2241,8 +2286,11 @@ class BufferStack
private
def cull!
# Remove empty buffers.
@stack.delete_if { |x| not VIM::evaluate_bool("bufexists(#{x})") }
# Remove empty and unlisted buffers.
@stack.delete_if { |x|
not (VIM::evaluate_bool("bufexists(#{x})") and
VIM::evaluate_bool("getbufvar(#{x}, '&buflisted')"))
}
end
# NOTE: very similar to Entry::compute_buffer_entries()

View file

@ -10,10 +10,11 @@
" Name Of File: lusty-juggler.vim
" Description: Dynamic Buffer Switcher Vim Plugin
" Maintainer: Stephen Bach <this-file@sjbach.com>
" Contributors: Juan Frias, Bartosz Leper, Marco Barberis
" Contributors: Juan Frias, Bartosz Leper, Marco Barberis, Vincent Driessen,
" Martin Wache, Johannes Holzfuß, Adam Rutkowski
"
" Release Date: June 2, 2010
" Version: 1.1.4
" Release Date: December 16, 2010
" Version: 1.2
"
" Usage:
" <Leader>lj - Opens the buffer juggler.
@ -52,18 +53,34 @@
" To cancel the juggler, press any of "q", "<ESC>", "<C-c",
" "<BS>", "<Del>", or "<C-h>".
"
" LustyJuggler can act very much like <A-Tab> window switching.
" To enable this mode, add the following line to your .vimrc:
"
" let g:LustyJugglerAltTabMode = 1
"
" Then, given the following mapping:
"
" noremap <silent> <A-s> :LustyJuggler<CR>
"
" Pressing "<A-s>" will launch the LustyJuggler with the
" previous buffer highlighted. Typing "<A-s>" again will cycle
" to the next buffer (in most-recently used order), and
" "<ENTER>" will open the highlighted buffer. For example, the
" sequence "<A-s><Enter>" will open the previous buffer, and
" "<A-s><A-s><Enter>" will open the buffer used just before the
" previous buffer, and so on.
"
" Bonus: This plugin also includes the following command, which will
" immediately switch to your previously used buffer:
"
" ":LustyJugglePrevious"
"
"
" This is similar to the ":b#" command, but accounts for the
" common situation where the previously used buffer (#) has
" been killed and is thus inaccessible. In that case, it will
" instead switch to the buffer used before that one (and on down
" the line if that buffer has been killed too).
"
"
"
" Install Details:
"
@ -138,7 +155,7 @@ if !has("ruby")
if !exists("g:LustyExplorerSuppressRubyWarning") ||
\ g:LustyExplorerSuppressRubyWarning == "0"
if !exists("g:LustyJugglerSuppressRubyWarning") ||
\ g:LustyJugglerSuppressRubyWarning == "0"
\ g:LustyJugglerSuppressRubyWarning == "0"
echohl ErrorMsg
echon "Sorry, LustyJuggler requires ruby. "
echon "Here are some tips for adding it:\n"
@ -312,6 +329,10 @@ module VIM
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&modified')")
end
def listed?
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&buflisted')")
end
def self.obj_for_bufnr(n)
# There's gotta be a better way to do this...
(0..VIM::Buffer.count-1).each do |i|
@ -340,6 +361,22 @@ module VIM
end
end
# Hack for wide CJK characters.
if VIM::exists?("*strwidth")
module VIM
def self.strwidth(s)
# strwidth() is defined in Vim 7.3.
evaluate("strwidth('#{single_quote_escape(s)}')").to_i
end
end
else
module VIM
def self.strwidth(s)
s.length
end
end
end
# Utility functions.
module LustyJ
@ -487,13 +524,19 @@ class LustyJuggler
end
def run
return if @running
if $lj_buffer_stack.length <= 1
VIM::pretty_msg("PreProc", "No other buffers")
return
end
# If already running, highlight next buffer
if @running and LustyJuggler::alt_tab_mode_active?
@last_pressed = (@last_pressed % $lj_buffer_stack.length) + 1;
print_buffer_list(@last_pressed)
return
end
return if @running
@running = true
# Need to zero the timeout length or pressing 'g' will hang.
@ -517,6 +560,7 @@ class LustyJuggler
map_key("<Tab>", ":call <SID>LustyJugglerKeyPressed('TAB')<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>")
@ -524,7 +568,8 @@ class LustyJuggler
map_key("<Del>", ":call <SID>LustyJugglerCancel()<CR>")
map_key("<C-h>", ":call <SID>LustyJugglerCancel()<CR>")
print_buffer_list()
@last_pressed = 2 if LustyJuggler::alt_tab_mode_active?
print_buffer_list(@last_pressed)
end
def key_pressed()
@ -532,12 +577,12 @@ class LustyJuggler
if @last_pressed.nil? and c == 'ENTER'
cleanup()
elsif @last_pressed and (c == @last_pressed or c == 'ENTER')
choose(@@KEYS[@last_pressed])
elsif @last_pressed and (@@KEYS[c] == @last_pressed or c == 'ENTER')
choose(@last_pressed)
cleanup()
else
print_buffer_list(@@KEYS[c])
@last_pressed = c
@last_pressed = @@KEYS[c]
print_buffer_list(@last_pressed)
end
end
@ -556,6 +601,7 @@ class LustyJuggler
unmap_key("<CR>")
unmap_key("<Tab>")
unmap_key("i")
unmap_key("q")
unmap_key("<Esc>")
unmap_key("<C-c>")
@ -569,6 +615,11 @@ class LustyJuggler
end
private
def self.alt_tab_mode_active?
return (VIM::exists?("g:LustyJugglerAltTabMode") and
VIM::evaluate("g:LustyJugglerAltTabMode").to_i != 0)
end
def print_buffer_list(highlighted_entry = nil)
# If the user pressed a key higher than the number of open buffers,
# highlight the highest (see also BufferStack.num_at_pos()).
@ -690,7 +741,7 @@ class BufferItem < BarItem
slash_color = @@SLASH_COLOR
end
pieces = @str.split(File::SEPARATOR, -1)
pieces = @str.split(File::SEPARATOR, -1)
@array = []
@array << dir_color
@ -993,8 +1044,11 @@ class BufferStack
private
def cull!
# Remove empty buffers.
@stack.delete_if { |x| not VIM::evaluate_bool("bufexists(#{x})") }
# Remove empty and unlisted buffers.
@stack.delete_if { |x|
not (VIM::evaluate_bool("bufexists(#{x})") and
VIM::evaluate_bool("getbufvar(#{x}, '&buflisted')"))
}
end
# NOTE: very similar to Entry::compute_buffer_entries()

View file

@ -15,10 +15,10 @@
" Rajendra Badapanda, cho45, Simo Salminen, Sami Samhuri,
" Matt Tolton, Björn Winckler, sowill, David Brown
" Brett DiFrischia, Ali Asad Lotia, Kenneth Love, Ben Boeckel,
" robquant
" robquant, lilydjwg, Martin Wache, Johannes Holzfuß
"
" Release Date: July 21, 2010
" Version: 3.1.1
" Release Date: December 16, 2010
" Version: 4.0
"
" Usage:
" <Leader>lf - Opens the filesystem explorer.
@ -59,6 +59,8 @@
"
" <C-n> select [n]ext match
" <C-p> select [p]revious match
" <C-f> select [f]orward one column
" <C-b> select [b]ack one column
"
" <C-u> clear prompt
"
@ -242,8 +244,8 @@ let g:loaded_lustyexplorer = "yep"
" Commands.
command LustyBufferExplorer :call <SID>LustyBufferExplorerStart()
command LustyFilesystemExplorer :call <SID>LustyFilesystemExplorerStart()
command LustyFilesystemExplorerFromHere :call <SID>LustyFilesystemExplorerFromHereStart()
command -nargs=? LustyFilesystemExplorer :call <SID>LustyFilesystemExplorerStart("<args>")
command LustyFilesystemExplorerFromHere :call <SID>LustyFilesystemExplorerStart(expand("%:p:h"))
command LustyBufferGrep :call <SID>LustyBufferGrepStart()
" Deprecated command names.
@ -269,12 +271,8 @@ nmap <silent> <Leader>lb :LustyBufferExplorer<CR>
nmap <silent> <Leader>lg :LustyBufferGrep<CR>
" Vim-to-ruby function calls.
function! s:LustyFilesystemExplorerStart()
ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_wd }
endfunction
function! s:LustyFilesystemExplorerFromHereStart()
ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_here }
function! s:LustyFilesystemExplorerStart(path)
exec "ruby LustyE::profile() { $lusty_filesystem_explorer.run_from_path('".a:path."') }"
endfunction
function! s:LustyBufferExplorerStart()

View file

@ -10,10 +10,11 @@
" Name Of File: lusty-juggler.vim
" Description: Dynamic Buffer Switcher Vim Plugin
" Maintainer: Stephen Bach <this-file@sjbach.com>
" Contributors: Juan Frias, Bartosz Leper, Marco Barberis
" Contributors: Juan Frias, Bartosz Leper, Marco Barberis, Vincent Driessen,
" Martin Wache, Johannes Holzfuß, Adam Rutkowski
"
" Release Date: June 2, 2010
" Version: 1.1.4
" Release Date: December 16, 2010
" Version: 1.2
"
" Usage:
" <Leader>lj - Opens the buffer juggler.
@ -52,18 +53,34 @@
" To cancel the juggler, press any of "q", "<ESC>", "<C-c",
" "<BS>", "<Del>", or "<C-h>".
"
" LustyJuggler can act very much like <A-Tab> window switching.
" To enable this mode, add the following line to your .vimrc:
"
" let g:LustyJugglerAltTabMode = 1
"
" Then, given the following mapping:
"
" noremap <silent> <A-s> :LustyJuggler<CR>
"
" Pressing "<A-s>" will launch the LustyJuggler with the
" previous buffer highlighted. Typing "<A-s>" again will cycle
" to the next buffer (in most-recently used order), and
" "<ENTER>" will open the highlighted buffer. For example, the
" sequence "<A-s><Enter>" will open the previous buffer, and
" "<A-s><A-s><Enter>" will open the buffer used just before the
" previous buffer, and so on.
"
" Bonus: This plugin also includes the following command, which will
" immediately switch to your previously used buffer:
"
" ":LustyJugglePrevious"
"
"
" This is similar to the ":b#" command, but accounts for the
" common situation where the previously used buffer (#) has
" been killed and is thus inaccessible. In that case, it will
" instead switch to the buffer used before that one (and on down
" the line if that buffer has been killed too).
"
"
"
" Install Details:
"
@ -138,7 +155,7 @@ if !has("ruby")
if !exists("g:LustyExplorerSuppressRubyWarning") ||
\ g:LustyExplorerSuppressRubyWarning == "0"
if !exists("g:LustyJugglerSuppressRubyWarning") ||
\ g:LustyJugglerSuppressRubyWarning == "0"
\ g:LustyJugglerSuppressRubyWarning == "0"
echohl ErrorMsg
echon "Sorry, LustyJuggler requires ruby. "
echon "Here are some tips for adding it:\n"

View file

@ -70,7 +70,7 @@ class BufferItem < BarItem
slash_color = @@SLASH_COLOR
end
pieces = @str.split(File::SEPARATOR, -1)
pieces = @str.split(File::SEPARATOR, -1)
@array = []
@array << dir_color

View file

@ -73,8 +73,11 @@ class BufferStack
private
def cull!
# Remove empty buffers.
@stack.delete_if { |x| not VIM::evaluate_bool("bufexists(#{x})") }
# Remove empty and unlisted buffers.
@stack.delete_if { |x|
not (VIM::evaluate_bool("bufexists(#{x})") and
VIM::evaluate_bool("getbufvar(#{x}, '&buflisted')"))
}
end
# NOTE: very similar to Entry::compute_buffer_entries()

View file

@ -106,6 +106,10 @@ class Display
VIM::command 'highlight link LustyFileWithSwap WarningMsg'
VIM::command 'highlight link LustyNoEntries ErrorMsg'
VIM::command 'highlight link LustyTruncated Visual'
if VIM::exists? '*clearmatches'
VIM::evaluate 'clearmatches()'
end
end
#
@ -144,6 +148,8 @@ class Display
VIM::command "#{map} <C-w> :call <SID>#{prefix}KeyPressed(23)<CR>"
VIM::command "#{map} <C-n> :call <SID>#{prefix}KeyPressed(14)<CR>"
VIM::command "#{map} <C-p> :call <SID>#{prefix}KeyPressed(16)<CR>"
VIM::command "#{map} <C-f> :call <SID>#{prefix}KeyPressed(6)<CR>"
VIM::command "#{map} <C-b> :call <SID>#{prefix}KeyPressed(2)<CR>"
VIM::command "#{map} <C-o> :call <SID>#{prefix}KeyPressed(15)<CR>"
VIM::command "#{map} <C-t> :call <SID>#{prefix}KeyPressed(20)<CR>"
VIM::command "#{map} <C-v> :call <SID>#{prefix}KeyPressed(22)<CR>"
@ -175,7 +181,7 @@ class Display
if col_index < col_count - 1
# Add spacer to the width of the column
rows[i] << (" " * (column_width - string.length))
rows[i] << (" " * (column_width - VIM::strwidth(string)))
rows[i] << @@COLUMN_SEPARATOR
end
end
@ -185,6 +191,7 @@ class Display
end
print_rows(rows, truncated)
row_count
end
def close
@ -252,7 +259,8 @@ class Display
column_widths = []
total_width = 0
strings.each_slice(optimal_row_count) do |column|
column_width = column.max { |a, b| a.length <=> b.length }.length
longest = column.max { |a, b| VIM::strwidth(a) <=> VIM::strwidth(b) }
column_width = VIM::strwidth(longest)
total_width += column_width
break if total_width > max_width

View file

@ -18,12 +18,13 @@ class Entry
@label = label
end
# NOTE: very similar to BufferStack::shorten_paths()
def self.compute_buffer_entries()
buffer_entries = []
$le_buffer_stack.numbers.each do |n|
o = VIM::Buffer.obj_for_bufnr(n)
next if o.nil?
next if (o.nil? or not o.listed?)
buffer_entries << self.new(o, n)
end

View file

@ -60,6 +60,26 @@ class Explorer
@selected_index = \
(@selected_index - 1) % @current_sorted_matches.size
refresh_mode = :no_recompute
when 6 # C-f (select right)
columns = (@current_sorted_matches.size.to_f / @row_count.to_f).ceil
cur_column = @selected_index / @row_count
cur_row = @selected_index % @row_count
new_column = (cur_column + 1) % columns
if (new_column + 1) * (cur_row + 1) > @current_sorted_matches.size
new_column = 0
end
@selected_index = new_column * @row_count + cur_row
refresh_mode = :no_recompute
when 2 # C-b (select left)
columns = (@current_sorted_matches.size.to_f / @row_count.to_f).ceil
cur_column = @selected_index / @row_count
cur_row = @selected_index % @row_count
new_column = (cur_column - 1) % columns
if (new_column + 1) * (cur_row + 1) > @current_sorted_matches.size
new_column = columns - 2
end
@selected_index = new_column * @row_count + cur_row
refresh_mode = :no_recompute
when 15 # C-o choose in new horizontal split
choose(:new_split)
when 20 # C-t choose in new tab
@ -102,8 +122,8 @@ class Explorer
on_refresh()
highlight_selected_index() if VIM::has_syntax?
@display.print @current_sorted_matches.map { |x| x.label }
@prompt.print
@row_count = @display.print @current_sorted_matches.map { |x| x.label }
@prompt.print Display.max_width
end
def create_explorer_window

View file

@ -25,21 +25,12 @@ class FilesystemExplorer < Explorer
super
end
def run_from_here
def run_from_path(path)
return if @running
start_path = if $curbuf.name.nil?
VIM::getcwd()
else
VIM::evaluate("expand('%:p:h')")
end
@prompt.set!(start_path + File::SEPARATOR)
run()
end
def run_from_wd
return if @running
@prompt.set!(VIM::getcwd() + File::SEPARATOR)
if path.empty?
path = VIM::getcwd()
end
@prompt.set!(path + File::SEPARATOR)
run()
end

View file

@ -39,13 +39,19 @@ class LustyJuggler
end
def run
return if @running
if $lj_buffer_stack.length <= 1
VIM::pretty_msg("PreProc", "No other buffers")
return
end
# If already running, highlight next buffer
if @running and LustyJuggler::alt_tab_mode_active?
@last_pressed = (@last_pressed % $lj_buffer_stack.length) + 1;
print_buffer_list(@last_pressed)
return
end
return if @running
@running = true
# Need to zero the timeout length or pressing 'g' will hang.
@ -69,6 +75,7 @@ class LustyJuggler
map_key("<Tab>", ":call <SID>LustyJugglerKeyPressed('TAB')<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>")
@ -76,7 +83,8 @@ class LustyJuggler
map_key("<Del>", ":call <SID>LustyJugglerCancel()<CR>")
map_key("<C-h>", ":call <SID>LustyJugglerCancel()<CR>")
print_buffer_list()
@last_pressed = 2 if LustyJuggler::alt_tab_mode_active?
print_buffer_list(@last_pressed)
end
def key_pressed()
@ -84,12 +92,12 @@ class LustyJuggler
if @last_pressed.nil? and c == 'ENTER'
cleanup()
elsif @last_pressed and (c == @last_pressed or c == 'ENTER')
choose(@@KEYS[@last_pressed])
elsif @last_pressed and (@@KEYS[c] == @last_pressed or c == 'ENTER')
choose(@last_pressed)
cleanup()
else
print_buffer_list(@@KEYS[c])
@last_pressed = c
@last_pressed = @@KEYS[c]
print_buffer_list(@last_pressed)
end
end
@ -108,6 +116,7 @@ class LustyJuggler
unmap_key("<CR>")
unmap_key("<Tab>")
unmap_key("i")
unmap_key("q")
unmap_key("<Esc>")
unmap_key("<C-c>")
@ -121,6 +130,11 @@ class LustyJuggler
end
private
def self.alt_tab_mode_active?
return (VIM::exists?("g:LustyJugglerAltTabMode") and
VIM::evaluate("g:LustyJugglerAltTabMode").to_i != 0)
end
def print_buffer_list(highlighted_entry = nil)
# If the user pressed a key higher than the number of open buffers,
# highlight the highest (see also BufferStack.num_at_pos()).

View file

@ -23,9 +23,16 @@ class Prompt
@input = ""
end
def print
def print(max_width = 0)
text = @input
# may need some extra characters for "..." and spacing
max_width -= 5
if max_width > 0 && text.length > max_width
text = "..." + text[(text.length - max_width + 3 ) .. -1]
end
VIM::pretty_msg("Comment", @@PROMPT,
"None", VIM::single_quote_escape(@input),
"None", VIM::single_quote_escape(text),
"Underlined", " ")
end

View file

@ -82,6 +82,10 @@ module VIM
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&modified')")
end
def listed?
VIM::nonzero? VIM::evaluate("getbufvar(#{number()}, '&buflisted')")
end
def self.obj_for_bufnr(n)
# There's gotta be a better way to do this...
(0..VIM::Buffer.count-1).each do |i|
@ -110,3 +114,19 @@ module VIM
end
end
# Hack for wide CJK characters.
if VIM::exists?("*strwidth")
module VIM
def self.strwidth(s)
# strwidth() is defined in Vim 7.3.
evaluate("strwidth('#{single_quote_escape(s)}')").to_i
end
end
else
module VIM
def self.strwidth(s)
s.length
end
end
end

View file

@ -37,7 +37,7 @@ hi Normal ctermfg=253 ctermbg=NONE
" Comment Group
" -------------
" any comment
hi Comment guifg=#238e23 gui=none
hi Comment guifg=#238e23 gui=italic
hi Comment ctermfg=34 cterm=none