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

Switch back focus to vim/neovim after inverse search from Sioyek #2894

Closed

Conversation

HuidaeCho
Copy link

@HuidaeCho HuidaeCho commented Mar 7, 2024

This PR addresses #2579 by copying \ 'xwin_id': 0, line from zathura.vim. It wasn't working for me in neovim. because xwin_id was missing in b:vimtex.viewer for sioyek.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

🤔 I'm not exactly sure what you want here. Can you be more explicit about what was not working and why this fixes it?

@HuidaeCho
Copy link
Author

HuidaeCho commented Mar 7, 2024

🤔 I'm not exactly sure what you want here. Can you be more explicit about what was not working and why this fixes it?

Sorry for not being clear about it. When I set let g:vimtex_view_method='sioyek' and hit \lv in neovim, vimtex does a forward search and switches the focus to sioyek. So far so good. Now, from sioyek, <F4> (synctex mode) and right-click does an inverse search, but the focus would stay on sioyek without this PR because s:viewer.xdo_check() returned false even with xdotool installed.

function! s:viewer.xdo_check() dict abort " {{{1
return executable('xdotool') && has_key(self, 'xwin_id')
endfunction

The xwin_id key was missing in b:vimtex.viewer from your test.vim in #2579, and I looked into zathura.vim. That file has 'xwin_id': 0, so I tried that in sioyek.vim and that fixed this focus issue. Now, on inverse search, focus switches back to neovim.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

Ok; but then I still think this is not quite enough, because xwin_id will never be set to any value other than 0. Notice

function! s:viewer._start(outfile) dict abort " {{{1
let self.cmd_start
\ = vimtex#view#zathura#cmdline(a:outfile, self.has_synctex, 1)
call vimtex#jobs#run(self.cmd_start)
call timer_start(500, { _ -> self.xdo_get_id() })
endfunction

There is no similar call to self.xdo_get_id() in the sioyek viewer code.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

Did you test that it works for you with this change?

@HuidaeCho
Copy link
Author

HuidaeCho commented Mar 7, 2024

Ok; but then I still think this is not quite enough, because xwin_id will never be set to any value other than 0. Notice

function! s:viewer._start(outfile) dict abort " {{{1
let self.cmd_start
\ = vimtex#view#zathura#cmdline(a:outfile, self.has_synctex, 1)
call vimtex#jobs#run(self.cmd_start)
call timer_start(500, { _ -> self.xdo_get_id() })
endfunction

There is no similar call to self.xdo_get_id() in the sioyek viewer code.

Did you test that it works for you with this change?

I see. I think you're right. This fix works for me just because I added the missing key, but xwin_id is not set to a real ID. I don't think this PR will work if I have multiple vimtex instances. I'll look into it more.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

Notice that it is much better to include all of the context in a single thread. You are referring to a full other thread. I believe you are thinking about my suggestion here: #2579 (comment), where I suggest adding this:

augroup init_vimtex
  autocmd!
  autocmd User VimtexEventViewReverse call b:vimtex.viewer.xdo_focus_vim()
augroup END

But this particular function does not look for xwin_id, so adding it is not necessary.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

This is the function we are using:

function! s:viewer.xdo_focus_vim() dict abort " {{{1
if !executable('xdotool') | return | endif
if !executable('pstree') | return | endif

The dependencies are only that you have xdotool and pstree; you don't need xwin_id in the sioyek viewer for this to work.

@HuidaeCho
Copy link
Author

Notice that it is much better to include all of the context in a single thread. You are referring to a full other thread. I believe you are thinking about my suggestion here: #2579 (comment), where I suggest adding this:

augroup init_vimtex
  autocmd!
  autocmd User VimtexEventViewReverse call b:vimtex.viewer.xdo_focus_vim()
augroup END

But this particular function does not look for xwin_id, so adding it is not necessary.

Are you planning to support this focus back for sioyek in vimtex, like for zathura? It would be great not to have to add your suggested setting in .vimrc.

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

The feature was never really requested (until now), so I've not considered it.

I'm a little bit skeptical, because it will only work for people with xdotool and pstree, and perhaps not everyone of those. In such cases, I usually prefer that people instead use the flexibility provided to configure it themselves. It's only 4 lines of code.

@HuidaeCho HuidaeCho closed this Mar 7, 2024
@HuidaeCho
Copy link
Author

The feature was never really requested (until now), so I've not considered it.

I'm a little bit skeptical, because it will only work for people with xdotool and pstree, and perhaps not everyone of those. In such cases, I usually prefer that people instead use the flexibility provided to configure it themselves. It's only 4 lines of code.

Closed the PR. I think my last question is.. Will your setting work for multiple instances of vimtex?

@lervag
Copy link
Owner

lervag commented Mar 7, 2024

Yes, I believe it will work for multiple instances. You should test it, though, as I'm not 100% sure.

@HuidaeCho
Copy link
Author

Yes, I believe it will work for multiple instances. You should test it, though, as I'm not 100% sure.

Just FYI, multiple instances don't work. Only one neovim instance receives the inverse search and focus.

@lervag
Copy link
Owner

lervag commented Mar 8, 2024

Ok, thanks for the info!

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

Successfully merging this pull request may close these issues.

2 participants