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

wincmd p unreliable #637

Closed
languitar opened this issue Dec 10, 2016 · 9 comments
Closed

wincmd p unreliable #637

languitar opened this issue Dec 10, 2016 · 9 comments

Comments

@languitar
Copy link
Contributor

languitar commented Dec 10, 2016

Explain the issue

As explained in mhinz/vim-signify#193 I have encountered a jumping cursor when combining fugitive, vimtex and an autocmd to update vim-signify. I could get rid of this issue, by applying the following patch to the vimtex code:

diff --git a/autoload/vimtex/latexmk.vim b/autoload/vimtex/latexmk.vim
index 939d192..bf340b9 100644
--- a/autoload/vimtex/latexmk.vim
+++ b/autoload/vimtex/latexmk.vim
@@ -346,6 +346,8 @@ function! vimtex#latexmk#errors_open(force) " {{{1
   if !exists('b:vimtex') | return | endif
   cclose
 
+  let winid = win_getid()
+
   let log = b:vimtex.log()
   if empty(log)
     if a:force
@@ -386,7 +388,7 @@ function! vimtex#latexmk#errors_open(force) " {{{1
   if s:open_quickfix_window
     botright cwindow
     if g:vimtex_quickfix_mode == 2
-      wincmd p
+      call win_gotoid(winid)
     endif
     redraw
   endif
@lervag
Copy link
Owner

lervag commented Dec 10, 2016

Interesting. I wasn't aware of the win_... functions. They seem to be relatively new. That makes it a little bit scary to use them, since it would/could lead to errors for people who use old Vim versions.

Perhaps we could fix this with "older" syntax? Perhaps we could use the more "standard" winnr() function and then execute l:winnr . 'wincmd p'?

@languitar
Copy link
Contributor Author

@mhinz used a conditional version in the experimental commit he prepared for me to test this. Use that function if it exists, else winnr. Maybe that could be way to go?

@mhinz
Copy link

mhinz commented Dec 10, 2016

win_getid() and win_gotoid() were both introduced in the same commit: 7.4.1557. Thus I just check if that function is available and fall back to using winnr()/wincmd p otherwise: mhinz/vim-signify@3a8b31d

That said, the fallback isn't 100% reliable as well, since window numbers can change when new windows open (or close). The reliable way for older versions would be setting a w:var and searching that window at the end by looping over winnr('$').

@lervag
Copy link
Owner

lervag commented Dec 14, 2016

Thanks, @mhinz! Is there a good reason not to just use the fall back in all cases? I'm doing that now, and if there is a good reason to use the newer functions if available, then I might add that later.

@lervag lervag closed this as completed in c79e7af Dec 14, 2016
@languitar
Copy link
Contributor Author

Thanks for fixing this!

@lervag
Copy link
Owner

lervag commented Dec 15, 2016

No problem. Thanks for reporting the problem :)

@languitar
Copy link
Contributor Author

Hm, seems I am back at this situation. Did anything change in the meantime that could influence what is happening here?

@languitar
Copy link
Contributor Author

Seems that I am hitting the unreliability @mhinz has explained. Any chance to go to the new API per default?

languitar added a commit to languitar/vimtex that referenced this issue Mar 22, 2017
Use window IDs to return to the window that is currently being edited
after opening the quickfix list if these functions are available. Else,
use the previous mechanism of window numbers.

This is related to the changes previously discussed in lervag#637.
@lervag
Copy link
Owner

lervag commented Mar 22, 2017

I think this should be fixed for you through the PR #735.

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

3 participants