Comments
-
Greg Hurrell
Thanks for the report. It's an interesting observation which I hadn't really noticed myself.
The reason why I chose to dispose of the match listing buffer in this way (ie. with
:bwipeout!
) is because I wasn't sure how merely hiding the buffer would interact with people's different Vim set-ups (ie. depending on whether they have'hidden'
or'nohidden'
set, depending on whether vim was compiled with the+listcmds
feature or not etc).I'm happy to have a play around with different approaches, although I am a little worried that it might not work for all set-ups; ie. the last thing I want is when someone tries to open a file using Command-T, that Vim beeps at them and tells them "No write since last change" (for the match listing buffer) or similar.
I suppose that setting
'bufhidden'
tohide
or perhapsunload
on the match listing buffer might address that. And then I can probably use:bunload!
instead of:bwipeout!
to get rid of the match listing.I'll have a look into it anyway; please do post if you have any other comments or suggestions.
-
Greg Hurrell
Ok, this is the patch I'm playing with at the moment. Seems to work for me but I am going to run with it for a while and see if I can discover any issues with it:
commit 01edbd47f51aac3479dfe5bb21348a7c02a19142 (HEAD, master) Author: Greg Hurrell <greg@hurrell.net> Date: Thu Nov 4 10:07:54 2010 +0100 Dispose of match listing using :bunload! rather than :bwipeout! 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 of the match listing and repeatedly using Command-T doesn't drive the buffer numbers up any more. For more info see: https://wincent.dev/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.dev/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: Greg Hurrell <greg@hurrell.net> diff --git a/ruby/command-t/match_window.rb b/ruby/command-t/match_window.rb index eae0f87..da08fa4 100644 --- a/ruby/command-t/match_window.rb +++ b/ruby/command-t/match_window.rb @@ -29,6 +29,7 @@ module CommandT @@selection_marker = '> ' @@marker_length = @@selection_marker.length @@unselected_marker = ' ' * @@marker_length + @@buffer = nil def initialize options = {} @prompt = options[:prompt] @@ -52,28 +53,35 @@ module CommandT ::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? @@ -94,11 +102,10 @@ module CommandT @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 @@ -197,7 +204,7 @@ module CommandT unlock clear @window.height = 1 - @buffer[1] = "-- #{msg} --" + @@buffer[1] = "-- #{msg} --" lock end @@ -231,7 +238,7 @@ module CommandT 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 @@ -252,10 +259,10 @@ module CommandT @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
-
Greg Hurrell
Ok, going to mark this as closed. The above change is already pushed out in the master branch, so if you want to try it out you can get it from the repo (git://git.wincent.dev/command-t.git), or you can wait until the next release.
Do let me know if you find any issues with it.
-
Greg Hurrell
Status changed:
- From: new
- To: closed
-
Nadav Samet
Thanks for the quick response! I've pulled from the master branch and it seems to be working great.
-
anonymous
Hi Wincent, I encounter this every time I use Command-t: Exception raised every time I try to use leader t ruby/command-t/match_window.rb:93
raise "Can't find GoToFile buffer" unless $curbuf.name.match
the name of the buffer is the buffer I am currently in, not GoToFile.
I commented the line for testing, and it kind of works but not for me: I use a lot of splits piled on top of eachother, the current one being maximized. When opening a file with (modified) command-t it obliterates all of them :(
Note: My usual usage is ctags and C-] I can replace only the current one with the new file. also, using C-w C-] I can open the definition in a new one.
seeing you say this: "The reason why I chose to dispose of the match listing buffer in this way (ie. with :bwipeout!) is because I wasn't sure how merely hiding the buffer would interact with people's different Vim set-ups " I thought this feedback might help.
Thanks, Dan Baragan
Add a comment
Comments are now closed for this issue.