Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-evaluate sameids after buffer is re-entered #998

Merged
merged 1 commit into from
Aug 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion autoload/go/guru.vim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
" guru.vim -- Vim integration for the Go guru.


func! s:RunGuru(mode, format, selected, needs_scope) range abort
"return with a warning if the binary doesn't exist
let bin_path = go#path#CheckBinPath("guru")
Expand Down Expand Up @@ -364,6 +363,12 @@ function! go#guru#SameIds(selected)
let pos = split(item, ':')
call matchaddpos('goSameId', [[str2nr(pos[-2]), str2nr(pos[-1]), str2nr(poslen)]])
endfor

if get(g:, "go_auto_sameids", 0)
" re-apply SameIds at the current cursor position at the time the buffer
" is redisplayed: e.g. :edit, :GoRename, etc.
autocmd BufWinEnter <buffer> nested call go#guru#SameIds(-1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is called because we call :e inside :GoRename, which loads the buffer and thus it triggers this line right ? I wonder if there is a case that doesn't remove the trigger below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly right. But the nice thing about this approach, is that it will do the right thing even the user does :edit.

I don't think there's a case that fails to remove the buffer-local autocommand; the only case I could think of is when the buffer is wiped out, but in that case the buffer-local autocommand will be removed by Vim.

endif
endfunction

function! go#guru#ClearSameIds()
Expand All @@ -373,6 +378,11 @@ function! go#guru#ClearSameIds()
call matchdelete(item['id'])
endif
endfor

" remove the autocmds we defined
if exists("#BufWinEnter<buffer>")
autocmd! BufWinEnter <buffer>
endif
endfunction

function! go#guru#ToggleSameIds(selected)
Expand Down