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

Unite added to jumplist when using -no-split #278

Closed
iauns opened this issue Jul 2, 2013 · 22 comments
Closed

Unite added to jumplist when using -no-split #278

iauns opened this issue Jul 2, 2013 · 22 comments

Comments

@iauns
Copy link

iauns commented Jul 2, 2013

Unite appears to be adding itself to the jumplist when using the the -no-split command. The unite command with which you can use to hopefully reproduce this behavior is below:

nnoremap <silent> <C-p> :<C-u>Unite -no-split -buffer-name=files file_mru  file_rec/async:!<CR>

I can replicate it by opening at least 3 files before looking at :jumps

screen shot 2013-07-01 at 7 06 23 pm

@Shougo
Copy link
Owner

Shougo commented Jul 2, 2013

OK. I get it.
But it is hard to fix it and it is not bug.

http://www.reddit.com/r/vim/comments/1hd2kr/replacing_all_the_things_with_unitevim/catyjj5

You should use :Unite jump instead of <C-o> or <C-i>.
It ignores unite buffer jump list.

@iauns
Copy link
Author

iauns commented Jul 2, 2013

I'll look into :Unite jump. Thanks Shougo.

@iauns iauns closed this as completed Jul 2, 2013
@justinmk
Copy link
Contributor

What about performing :bwipeout! on the unite buffer after it is exited? Would it make sense to add this to unite for no-split behavior?

@justinmk
Copy link
Contributor

I wrote a function to experiment with this. It seems to be working nicely. ctrl-o and ctrl-i no longer jump into old unite buffers.

This function is a bit overkill because it loops through all the (un)listed buffers. If the bwipeout approach is ok with you @Shougo, then I would be happy to find a more thoughtful way to modify unite.vim so that it only tries to bwipeout its buffer after it was closed.

I suspect this also won't play nicely with :UniteResume, but we could make the bwipeout behavior optional. I personally don't use :UniteResume, and ctrl-o/ctrl-i are more important to me.

function! s:clearUniteBuffers()
  "find [unite] or *unite* buffers to be wiped-out
  let unitebuffs = filter(range(1, bufnr('$')), 
        \ '"nofile" ==# getbufvar(v:val, "&buftype") 
        \  && -1 == index(displayedbufs, v:val) 
        \  && bufname(v:val) =~# ''*unite*\|\[unite\]''')

  " obliterate the buffers and their related state (marks especially).
  if !empty(unitebuffs)
    exe 'bwipeout! '.join(unitebuffs, ' ')
  endif
endfunction

autocmd BufEnter * silent call <sid>clearUniteBuffers()

@Shougo
Copy link
Owner

Shougo commented Aug 19, 2013

I suspect this also won't play nicely with :UniteResume, but we could make the bwipeout behavior optional. I personally don't use :UniteResume, and ctrl-o/ctrl-i are more important to me.

If you don't want to use "UniteResume", you can use it.
But I often use "UniteResume". I cannot merge your function.

@justinmk
Copy link
Contributor

justinmk commented Sep 3, 2013

@Shougo , would you consider removing the default mapping of ctrl-i ? Currently, in a unite buffer, ctrl-i is mapped to <Plug>(unite_choose_action). But if we are to treat unite buffers as first-class buffers, including preservation of unite locations in the jumps list, then at least ctrl-i and ctrl-o should not be overridden. It is surprising when moving through the jumplist, if one jumps into a unite buffer with ctrl-i, suddenly ctrl-i has a different meaning (it selects a unite action). It would improve unite's out-of-the-box experience if it did not override ctrl-i.

@Shougo
Copy link
Owner

Shougo commented Sep 3, 2013

No. But you can unmap this mapping.

@justinmk
Copy link
Contributor

justinmk commented Sep 3, 2013

I know. But I think it is good to improve the "default" experience for new users.

@Shougo
Copy link
Owner

Shougo commented Sep 3, 2013

No. I don't want to change default mappings.
And unite add unite buffer to jumplist. So you cannot use normal <C-i>/<C-o>.

@pinkchry
Copy link

So I tried

autocmd BufLeave _unite_buffer bwipeout!

to clean up the unite buffers and it works pretty well. However this doesn't work with -auto-preview. I tried BufWinLeave and BufHidden, but get errors. Any suggestions?

Thanks

@justinmk
Copy link
Contributor

@pinkchry Wow, I wish I had thought of that :)

Regarding -auto-preview, I've never used it, but I assume it opens a preview window, which isn't really a buffer, so I don't think it would add to your jumplist. Does it?

@pinkchry
Copy link

What I really wanted to do was

autocmd BufLeave unite bwipeout!

However that causes the errors with -auto-preview. I guess it somehow deletes the preview window and auto preview does not work after that. ':Unite file' creates buffers with the name "[unite] - default" for which this doesn't work.

@justinmk
Copy link
Contributor

There seem to be a couple of problems with your approach:

  • any buffer with "unite" in the name is going to get wiped out (correct me if I'm wrong)
  • it closes the window, not just the buffer. That's undesirable if you use -no-split

I simplified & improved the function in my comment above. You may want to use it instead.

@pinkchry
Copy link

There was a formatting mistake in the autocmd. It should be

autocmd BufLeave *unite* bwipeout!

I use -no-split all the time, and this just kills the buffer and not the window. The problem still occurs with -auto-preview though.

@pinkchry
Copy link

I believe I've found something that works for my workflow and hopefully for you. Try this

autocmd BufLeave \[unite\]* set bufhidden=wipe

@justinmk
Copy link
Contributor

Nice! That seems to work. Thank you!

Here's a slightly more robust version (avoid data loss even in rare edge cases):

autocmd BufLeave \[unite\]* if "nofile" ==# &buftype | setlocal bufhidden=wipe | endif

Maybe the relevant FAQ should include your fix: https://github.com/Shougo/unite.vim/blob/master/doc/unite.txt#L3415

@Shougo
Copy link
Owner

Shougo commented Sep 16, 2013

Unite buffer name may be changed in later version. I don't recommend to use it.

Maybe the relevant FAQ should include your fix: https://github.com/Shougo/unite.vim/blob/master/doc/unite.txt#L3415

OK.

@kopischke
Copy link

A slightly more selective take on @justinmk's version would be this:

augroup unite_wipe_nosplit
  autocmd!
  autocmd BufLeave *
  \ if empty(&bufhidden)
  \ && &buftype  ==# 'nofile'
  \ && &filetype ==# 'unite'
  \ && !unite#get_current_unite().context.split |
  \   setlocal bufhidden=wipe |
  \ endif
augroup END

This doesn’t rely on the buffer name and exclusively wipes -no-split buffers, preserving the ability to resume other Unite buffers. It also leaves buffers that already set bufhidden alone.

@justinmk
Copy link
Contributor

@kopischke Very nice. @Shougo I've been using the bufhidden=wipe approach for almost a year without any problems. Would you consider including @kopischke 's version in unite? Or maybe adding a unite#get_current_unite().context.wipe option to be used with this approach?

@Shougo
Copy link
Owner

Shougo commented Aug 13, 2014

OK. I will try it. But I think if the feature is used, you cannot use :UniteResume feature.

Shougo added a commit that referenced this issue Aug 15, 2014
@Shougo
Copy link
Owner

Shougo commented Aug 15, 2014

I added wipe option.

@justinmk
Copy link
Contributor

Thanks @Shougo , I'll use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants