xavierd / clang_complete

Vim plugin that use clang for completing C/C++ code.
http://www.vim.org/scripts/script.php?script_id=3302
1.95k stars 308 forks source link

jump back persistent storage #342

Open bbudzon opened 11 years ago

bbudzon commented 11 years ago

I tried to find a duplicate of this and was unable so I am opening this. I have duplicated this behavior in a simple test program (it seems almost any code / jump will do it) and have been unable to reproduce this with ctags or cscope so it appears to not be vim related and more likely to be related to the clang_complete plugin itself.

If I open a test.cpp with a foo1, foo2 and main function, where main calls foo1 and foo2 and returns, and if I jump to foo1, jump back, and jump to foo2 and exit, when I re-open the test.cpp with vim using the clang_complete tag / code navigation setup, if I do not ever jump and immediately press the jump back keyboard shortcut it starts jumping back down the tag stack.

I believe that this behaviour should be similar to ctags/cscope in that the tag stack doesn't persist after vim has been exited. Furthermore, it doesn't seem that the tag stack is left in a condition that it should be in even if it is persistent. For example (and using the example above):

  1. open test.cpp in vim (the tag stack is should be empty)
  2. jump to foo1 (the tag stack should have one element)
  3. jump back to main (the tag stack should be empty again)
  4. jump to foo2 (the tag stack should have one element)
  5. exit If the stack was persistent, when I open test.cpp there should be one element on the stack (the ":tags" command seems to never show the stack so I assume we are implementing one internally). However, I can jump back 5-6 times. Much more than I had ever jumped forward in the first place.

I also just ran a quick test and renamed test.cpp to test2.cpp, and opened up the file. Without performing any vim commands (not even moving the cursor), I pressed the jump back keyboard shortcut. This jumped me back to a new buffer for test.cpp and gave the error "E19: Mark has invalid line number".

In my downtime, I can try to look into this but I have never contributed before (although I did want to some time ago) so hopefully the learning curve isn't too steep and the code is fairly easy to jump into to.

bbudzon commented 11 years ago

Ok, so I looked into the plugin and found out its using jumplists, not a tag stack. Jumplists are persistent from vim's point of view (they are written to the .viminfo file) and each window does not give each split its own jumplist. It seems like it would take quite a bit of work to re-write this and that this is probably just the way it is going to be for some time. We could possibly use an autocommand to clear out the jumplist at vim's exit but this still wouldn't solve the issue of split windows behaving quite a bit differently than tags would.

And this may be more of a personal opinion or bias as I have never used jump lists before but use tags constantly, so I expected tag like behavior :P

bbudzon commented 11 years ago

Ok, so after spending a little more time I found out that each window does get its own jumplist even though it all seems to go into the same .viminfo file. A decent workaround to get more "tag" like behavior is to clear the jumplist on vim exit. I just stuck this in my vimrc: au VimLeave * silent !sed -i "/^-'/d" ~/.viminfo

May be a better way to do this but anywho, this should be closed out