Skip to content

Commit

Permalink
Dispose of match listing using :bunload! rather than :bwipeout!
Browse files Browse the repository at this point in the history
Previously we created a new buffer every time we showed the match
listing and then disposed of it each time with :bwipeout!. This caused
the buffer numbers to steadily grow.

Now, we dispose of the match listing using :bunload!; this frees the
contents of the buffer and closes the window, but the buffer sticks
around and can be re-used next time we show the match listing. In this
way we always have a stable buffer number for the match listing and
repeatedly using Command-T doesn't drive the buffer numbers up any more.

For more info see:

  https://wincent.com/issues/1724

One concern with this change is that it increases our reliance on the
accuracy of the buffer number, and there is a known bug in Vim 7.3 when
built with --enable-largefile; see this ticket for full details:

  https://wincent.com/issues/1617

If you are affected by this bug the solution is to build Vim using
--disable-largefile. Until the issue gets fixed upstream I am thinking
of adding a workaround in Command-T (falling back to buffer name rather
than number for people with a broken Vim).

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information
wincent committed Nov 4, 2010
1 parent 4d08178 commit 1e4d514
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions ruby/command-t/match_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MatchWindow
@@selection_marker = '> '
@@marker_length = @@selection_marker.length
@@unselected_marker = ' ' * @@marker_length
@@buffer = nil

def initialize options = {}
@prompt = options[:prompt]
Expand All @@ -52,28 +53,35 @@ def initialize options = {}
::VIM::set_option 'sidescrolloff=0' # don't sidescroll automatically
::VIM::set_option 'noequalalways' # don't auto-balance window sizes

# create match window and set it up
# show match window
split_location = options[:match_window_at_top] ? 'topleft' : 'botright'
split_command = "silent! #{split_location} 1split GoToFile"
[
split_command,
'setlocal bufhidden=delete', # delete buf when no longer displayed
'setlocal buftype=nofile', # buffer is not related to any file
'setlocal nomodifiable', # prevent manual edits
'setlocal noswapfile', # don't create a swapfile
'setlocal nowrap', # don't soft-wrap
'setlocal nonumber', # don't show line numbers
'setlocal nolist', # don't use List mode (visible tabs etc)
'setlocal foldcolumn=0', # don't show a fold column at side
'setlocal foldlevel=99', # don't fold anything
'setlocal nocursorline', # don't highlight line cursor is on
'setlocal nospell', # spell-checking off
'setlocal nobuflisted', # don't show up in the buffer list
'setlocal textwidth=0' # don't hard-wrap (break long lines)
].each { |command| ::VIM::command command }

# sanity check: make sure the buffer really was created
raise "Can't find buffer" unless $curbuf.name.match /GoToFile/
if @@buffer # still have buffer from last time
::VIM::command "silent! #{split_location} #{@@buffer.number}sbuffer"
raise "Can't re-open GoToFile buffer" unless $curbuf.number == @@buffer.number
$curwin.height = 1
else # creating match window for first time and set it up
split_command = "silent! #{split_location} 1split GoToFile"
[
split_command,
'setlocal bufhidden=unload', # unload buf when no longer displayed
'setlocal buftype=nofile', # buffer is not related to any file
'setlocal nomodifiable', # prevent manual edits
'setlocal noswapfile', # don't create a swapfile
'setlocal nowrap', # don't soft-wrap
'setlocal nonumber', # don't show line numbers
'setlocal nolist', # don't use List mode (visible tabs etc)
'setlocal foldcolumn=0', # don't show a fold column at side
'setlocal foldlevel=99', # don't fold anything
'setlocal nocursorline', # don't highlight line cursor is on
'setlocal nospell', # spell-checking off
'setlocal nobuflisted', # don't show up in the buffer list
'setlocal textwidth=0' # don't hard-wrap (break long lines)
].each { |command| ::VIM::command command }

# sanity check: make sure the buffer really was created
raise "Can't find GoToFile buffer" unless $curbuf.name.match /GoToFile/
@@buffer = $curbuf
end

# syntax coloring
if VIM::has_syntax?
Expand All @@ -94,11 +102,10 @@ def initialize options = {}
@selection = nil
@abbrev = ''
@window = $curwin
@buffer = $curbuf
end

def close
::VIM::command "bwipeout! #{@buffer.number}"
::VIM::command "bunload! #{@@buffer.number}"
restore_window_dimensions
@settings.restore
@prompt.dispose
Expand Down Expand Up @@ -197,7 +204,7 @@ def print_error msg
unlock
clear
@window.height = 1
@buffer[1] = "-- #{msg} --"
@@buffer[1] = "-- #{msg} --"
lock
end

Expand Down Expand Up @@ -231,7 +238,7 @@ def match_text_for_idx idx
def print_match idx
return unless VIM::Window.select(@window)
unlock
@buffer[idx + 1] = match_text_for_idx idx
@@buffer[idx + 1] = match_text_for_idx idx
lock
end

Expand All @@ -252,10 +259,10 @@ def print_matches
@window.height = actual_lines
(1..actual_lines).each do |line|
idx = line - 1
if @buffer.count >= line
@buffer[line] = match_text_for_idx idx
if @@buffer.count >= line
@@buffer[line] = match_text_for_idx idx
else
@buffer.append line - 1, match_text_for_idx(idx)
@@buffer.append line - 1, match_text_for_idx(idx)
end
end
lock
Expand Down

0 comments on commit 1e4d514

Please sign in to comment.