lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.45k stars 388 forks source link

[SOLVED] Focus the terminal when doing inverse search #2971

Closed DaitiDay closed 3 months ago

DaitiDay commented 3 months ago

Description

As for the title, inverse search works fine (I'm using sioyek). The cursor gets put to the correct location in vim, but the terminal does not get focused. Following the suggestion in #2579 I've tried to add the following autocommand to my neovim config:

local group = vim.api.nvim_create_augroup('vimtex', { clear = true })
vim.api.nvim_create_autocmd('VimtexEventViewReverse', { command = "call b:vimtex.viewer.xdo_focus_vim()", group = group })

with no success. Anyone can help me pointing out what I'm doing wrong?

Steps to reproduce

Not relevant.

Expected behavior

Clicking on text in sioyek should switch focus to the terminal and put the cursor on the correct line in the tex file.

Actual behavior

The cursor gets put on the correct line in the tex file but the terminal does not get focus.

Do you use a latexmkrc file?

no

VimtexInfo

System info:
  OS: Linux 6.9.3-arch1-1
  Vim version: NVIM v0.10.0
  Has clientserver: true
  Servername: /run/user/1000/nvim.1820.0

VimTeX project: main
  base: main.tex
  root: /home/daiti/tmp
  tex: /home/daiti/tmp/main.tex
  main parser: current file verified
  document class: article
  packages: expl3 l3keys2e lipsum
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    aux_dir: ./build
    callback: 1
    continuous: 1
    executable: latexmk
    job: 
      jobid: 6
      output: /tmp/nvim.daiti/2IMbsC/0
      cmd: max_print_line=2000 latexmk -verbose -file-line-error -synctex=1 -interaction=nonstopmode  -pdf -emulate-aux-dir -auxdir=./build -pvc -pvctimeout- -view=none -e '$compiling_cmd = ($compiling_cmd ? $compiling_cmd . " ; " : "") . "echo vimtex_compiler_callback_compiling"' -e '$success_cmd = ($success_cmd ? $success_cmd . " ; " : "") . "echo vimtex_compiler_callback_success"' -e '$failure_cmd = ($failure_cmd ? $failure_cmd . " ; " : "") . "echo vimtex_compiler_callback_failure"' 'main.tex'
      pid: 2015
  viewer: sioyek
    job: 
      pid: 2027
      cmd: sioyek  --inverse-search "/usr/bin/nvim --headless -c \"VimtexInverseSearch %2 '%1'\"" --forward-search-file '/home/daiti/tmp/main.tex' --forward-search-line 1 '/home/daiti/tmp/main.pdf'
    cmd_start: sioyek  --inverse-search "/usr/bin/nvim --headless -c \"VimtexInverseSearch %2 '%1'\"" --forward-search-file '/home/daiti/tmp/main.tex' --forward-search-line 1 '/home/daiti/tmp/main.pdf'
  qf method: LaTeX logfile
lervag commented 3 months ago

As for the title, inverse search works fine (I'm using sioyek). The cursor gets put to the correct location in vim, but the terminal does not get focused. Following the suggestion in #2579 I've tried to add the following autocommand to my neovim config:

local group = vim.api.nvim_create_augroup('vimtex', { clear = true })
vim.api.nvim_create_autocmd('VimtexEventViewReverse', { command = "call b:vimtex.viewer.xdo_focus_vim()", group = group })

with no success. Anyone can help me pointing out what I'm doing wrong?

Yes, sure. The problem is that the autocommand is not correct. Try this:

local group = vim.api.nvim_create_augroup('vimtex', {})
vim.api.nvim_create_autocmd('User', {
  pattern = 'VimtexEventViewReverse',
  group = group,
  command = "call b:vimtex.viewer.xdo_focus_vim()"
})

The point is that VimtexEvent... is a pattern for the User event. Notice, you don't need clear = true, since it is the default.

DaitiDay commented 3 months ago

It works 😄 thank you for the help. I had to change the command cause my window manager wasn't switching focus with certain layouts, but the pattern key fixed the main problem. I'll close the issue as solved but I suggest that the autocmd snippet be added to the documentation. Thank you again 👍🏻

lervag commented 3 months ago

It works 😄

Great, I'm glad to hear it!

thank you for the help.

No problem :)

I had to change the command cause my window manager wasn't switching focus with certain layouts, but the pattern key fixed the main problem. I'll close the issue as solved but I suggest that the autocmd snippet be added to the documentation.

I've added a couple of snippets to the event examples. Let me know if you think it is not good enough ;)