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

VimtexInfo throwing error on MSYS2 shell + unable to compile #2554

Closed
stanle-cs opened this issue Nov 1, 2022 · 46 comments
Closed

VimtexInfo throwing error on MSYS2 shell + unable to compile #2554

stanle-cs opened this issue Nov 1, 2022 · 46 comments
Labels

Comments

@stanle-cs
Copy link

stanle-cs commented Nov 1, 2022

Description

Unable to run \ll on Windows, error throw:
/usr/bin/bash: /s: No such file or directory

Steps to reproduce

  1. Install vimtex on Windows
  2. Open a .tex file
  3. Check VimtexInfo

Expected behavior

System info:
OS: USSNFL123 (Microsoft Windows 10 Pro)
Vim version: NVIM v0.9.0-dev-206+gc3aba403c
Has clientserver: true
Servername: \.\pipe\nvim.19508.0

Actual behavior

System info:
4 OS: Windows (['/usr/bin/bash: /s: No such file or directory'])
3 Vim version: NVIM v0.9.0-dev-206+gc3aba403c
2 Has clientserver: true
1 Servername: \.\pipe\nvim.1612.0

Do you use a latexmkrc file?

No

VimtexInfo

System info:
    4   OS: Windows (['/usr/bin/bash: /s: No such file or directory'])
    3   Vim version: NVIM v0.9.0-dev-206+gc3aba403c
    2   Has clientserver: true
    1   Servername: \\.\pipe\nvim.1612.0
  6
    1 VimTeX project: ttd_upstream
    2   base: ttd_upstream.tex
    3   root: C:\msys64\home\XX\LaTeX\ttd_upstream
    4   tex: C:\msys64\home\XX\LaTeX\ttd_upstream\ttd_upstream.tex
    5   main parser: current file verified
    6   document class: article
    7   packages: fontspec
    8   compiler: latexmk
    9     engine: -pdf
   10     options:
   11       -xelatex
   12       -file-line-error
   13       -synctex=1
   14       -interaction=nonstopmode
   15     build_dir: ttd_upstream
   16     callback: 1
   17     continuous: 1
@stanle-cs stanle-cs added the bug label Nov 1, 2022
@stanle-cs stanle-cs changed the title VimtexInfo throwing error on MSYS2 shell VimtexInfo throwing error on MSYS2 shell + unable to compile Nov 1, 2022
@lervag
Copy link
Owner

lervag commented Nov 1, 2022

Strange. It seems to be some problem with the 'shell' setting. If you open neovim and do :!echo "test", what does it do?

I'm not sure I've heard of anyone using MSYS2 with neovim and VimTeX before. Did you consider to use WSL instead? I believe it should be a much better solution than MSYS2 these days.

@stanle-cs
Copy link
Author

Hi lervag, first off thank you for your awesome work on this plugin.

I have a niche use case for the plugin, but one that I'm sure can be a lot more common: I'm using my work computer to draft LaTeX documents to communicate with my peers. As such, I have to use Windows, and I don't have admin privilege. That means no WSL.

I can install MSYS2 as it does not require admin right. I much prefer using the MSYS2 shell since it will display all the symbols that vim-airline use. This leads to the problem we see above.

As for the test:

:!echo "test"
"test"

It took me a while to find a setting that satisfy the health#coc#check. My settings are:

let &shell='"C:\\Windows\\System32\\cmd.exe"'
let &shellcmdflag="/s /c"
set shellxquote=\"

Can you suggest any patches for the MSYS2 shell? I can apply them myself if it's too niche.

@lervag
Copy link
Owner

lervag commented Nov 1, 2022

I'm glad to hear you find VimTeX to be useful! :)

So, let's look into this. It may take some back and forth to debug, but I believe we should be able to figure something out. First off, while testing, we need to ensure that the caching does not "hide" any bugs or improvements. So, could you add let g:vimtex_cache_persistent = 0 to your config - this should be removed when things work, because the caching is very useful for performance reasons. You may also want to do :VimtexClearCache ALL when we get things to work, again, to make sure the caching did not prevent anything.

The lines in the VimTeX code that are generating the \li output for the OS: line are here:

if !exists('s:win_info')
let s:win_info = vimtex#jobs#cached('systeminfo')
endif
try
let l:name = vimtex#util#trim(matchstr(s:win_info[1], ':\s*\zs.*'))
let l:version = vimtex#util#trim(matchstr(s:win_info[2], ':\s*\zs.*'))
return l:name . ' (' . l:version . ')'
catch
return 'Windows (' . string(s:win_info) . ')'
endtry

Thus, the call that is problematic is this: vimtex#jobs#cached('systeminfo'). We want to investigate this, and it is not so deep. First, we can avoid the cache, so, if you open neovim in MSYS2 and run :echo vimtex#jobs#capture('systeminfo'), it should replicate the error message - I think. Please confirm!

@lervag
Copy link
Owner

lervag commented Nov 1, 2022

The first step is to fully recognize exactly where things go wrong. I believe these lines are the ones that generate the error:

function! s:neovim_win_capture(cmd) abort " {{{1
let s:saveshell = [&shell, &shellcmdflag, &shellslash]
set shell& shellcmdflag& shellslash&
let l:output = systemlist('cmd /s /c "' . a:cmd . '"')
let [&shell, &shellcmdflag, &shellslash] = s:saveshell
return l:output
endfunction
" }}}1

You could easily inspect that by adding e.g. unsilent echo 'DEBUG SEE HERE' somewhere inside and verifying if it prints when running :call vimtex#jobs#capture('systeminfo'). However, this may be where the problem actually happens, because I'm not sure if neovim in MSYS2 is recognized as windows. I.e., what's the output of :echo has('win32') in your neovim? If it is 0, then this is the code that is running:

function! s:neovim_unix_capture(cmd) abort " {{{1
return systemlist(['sh', '-c', a:cmd])
endfunction
" }}}1

@lervag
Copy link
Owner

lervag commented Nov 1, 2022

Finally, it would be very useful if you could create a minimal example. Something along these lines: Create a test.vim with the following content:

set nocompatible
" Change the below to the correct path to VimTeX
set runtimepath^=~/.local/plugged/vimtex
filetype plugin indent on
syntax enable

" Possibly add settings like these (whatever is required to reproduce the
" issue)
let &shell='"C:\\Windows\\System32\\cmd.exe"'
let &shellcmdflag="/s /c"
set shellxquote=\"

" Run something that fails with the same issue as the original problem:
" Current hypothesis is that this is "systeminfo", but that needs
" verification.
echo vimtex#jobs#capture('systeminfo')

quitall

Now, in an MSYS2 terminal, you would do nvim --headless --clean -u test.vim. If we can successfully create such a minimal example, it will be much easier working towards some kind of solution.

@stanle-cs
Copy link
Author

stanle-cs commented Nov 1, 2022

Alrighty, here are the results:
Cache cleared and persistence off

:echo vimtex#jobs#capture('systeminfo')
['/usr/bin/bash: /s: No such file or directory']
:call vimtex#jobs#capture('systeminfo')
(no output)
:echo has('win32')
1

Then finally the .minimalvimrc:

  1   set nocompatible
    1 let &runtimepath  = 'C:/Users/XX/AppData/Local/nvim-data/plugged/vimtex' . &runtimepath
    2 filetype plugin indent on
    3 syntax enable
    4 " Add relevant options and VimTeX configuration below.
    5 " Possibly add settings like these (whatever is required to reproduce the
    6 " issue)
    7 let &shell='"C:\\Windows\\System32\\cmd.exe"'
    8 let &shellcmdflag="/s /c"
    9 set shellxquote=\"
   10
   11 " Run something that fails with the same issue as the original problem:
   12 " Current hypothesis is that this is "systeminfo", but that needs
   13 " verification.
   14 echo vimtex#jobs#capture('systeminfo')
   15
   16 quitall
~
$ vim --headless --clean -u ~/.minimalvimrc
Error detected while processing C:/msys64/home/XX/.minimalvimrc:
line   15:
E117: Unknown function: vimtex#jobs#capture

I hope this can help?

@stanle-cs
Copy link
Author

stanle-cs commented Nov 1, 2022

False alarm on the last test! I didn't follow your minimal vimrc somehow!

Replaced

let &runtimepath  = 'C:/Users/XX/AppData/Local/nvim-data/plugged/vimtex' . &runtimepath

with

 set runtimepath^=C:\\Users\\XX\\AppData\\Local\\nvim-data\\plugged\\vimtex

Result:

$ vim --headless --clean -u ~/.minimalvimrc
['/usr/bin/bash: /s: No such file or directory']

@lervag
Copy link
Owner

lervag commented Nov 2, 2022

Great, having the minimal vimrc "working" is a very useful starting point!

Does changing the &shell option(s) have any effect?

So, next point is to ensure we know which point is being executed. vimtex#jobs#capture on neovim with Windows (has('win32')) should run the code I referenced above, but for some reason the :unsilent echo ... statement I asked you to add did not seem to trigger. It seems to me that you might be capable to partly debug this already on your side. The easiest trick is print-debugging. Can you add e.g. :unsilent echo "DBG 1" at the first point we know is executed, then moving things deeper until we reach the spot where things go wrong? Let me know if this is unclear, I'll try and explain better.

@stanle-cs
Copy link
Author

Hi lervag,

Sorry, work has been super busy this week, so I didn't have a chance to look into it until today. I think I understood what you said now. Earlier in the test, I somehow forgot to put the DEBUG echo into the code. I tried the new neovim.vim file like follow:

 function! s:neovim_win_capture(cmd) abort " {{{1
    1   unsilent echo 'DEBUG SEE HERE: 1'
    2   let s:saveshell = [&shell, &shellcmdflag, &shellslash]
    3   set shell& shellcmdflag& shellslash&
    4
    5   unsilent echo 'DEBUG SEE HERE: 2'
    6   let l:output = systemlist('cmd /s /c "' . a:cmd . '"')
    7
    8   unsilent echo 'DEBUG SEE HERE: 3'
    9   let [&shell, &shellcmdflag, &shellslash] = s:saveshell
   10
   11   unsilent echo 'DEBUG SEE HERE: 4'
   12
   13   return l:output
   14 endfunction

The result is:

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG SEE HERE: 1
DEBUG SEE HERE: 2
DEBUG SEE HERE: 3
DEBUG SEE HERE: 4
['/usr/bin/bash: /s: No such file or directory']

@stanle-cs
Copy link
Author

stanle-cs commented Nov 5, 2022

Also, I was curious to see which shell is being used, so I add:

16 function! s:neovim_win_capture(cmd) abort " {{{1
   15   unsilent echo 'DEBUG SEE HERE: 1, $shell: ' $shell
   14   let s:saveshell = [&shell, &shellcmdflag, &shellslash]
   13   set shell& shellcmdflag& shellslash&
   12
   11   unsilent echo 'DEBUG SEE HERE: 2, $shell: ' $shell
   10   let l:output = systemlist('cmd /s /c "' . a:cmd . '"')
    9
    8   unsilent echo 'DEBUG SEE HERE: 3, $shell: ' $shell
    7   let [&shell, &shellcmdflag, &shellslash] = s:saveshell
    6
    5   unsilent echo 'DEBUG SEE HERE: 4, $shell: ' $shell
    4
    3   return l:output
    2 endfunction

And get this result:

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG SEE HERE: 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 2, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 3, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 4, $shell:  C:\msys64\usr\bin\bash.exe
['/usr/bin/bash: /s: No such file or directory']

So looks like the let &shell="...\\cmd.exe" is not honored by vimtex.

@lervag
Copy link
Owner

lervag commented Nov 5, 2022

Sorry, work has been super busy this week, so I didn't have a chance to look into it until today.

No worries!

I think I understood what you said now. Earlier in the test, I somehow forgot to put the DEBUG echo into the code. I tried the new neovim.vim file like follow: …

The result is: …

Also, I was curious to see which shell is being used, so I add:

Thanks! That's good thinking. This means we know much about where our problem lies!

What's surprising to me is this:

DEBUG SEE HERE: 1, $shell: C:\msys64\usr\bin\bash.exe

VimTeX does not change the &shell* settings permanently. It only temporarily changes them. Thus, I would have expected the 1st and 4th debug outputs to be your original shell setting. My hypothesis is therefore that these settings are changed by something else (not VimTeX).

When you ran these tests, did you use the minimal example we created earlier? I.e., did you run vim --headless --clean -u ~/.minimalvimrc? (I notice you used vim, but I guess that's aliased to nvim or you just typoed?)

If you open a .tex file (doesn't matter which) with your regular vimrc file, then do :verbose set shell - what's the output?

@stanle-cs
Copy link
Author

stanle-cs commented Nov 5, 2022

Ahh I think you're onto something here. And yes, vim is an alias for nvim v0.9.0.

For some reasons, the set &shell=....\\cmd.exe will satisfy health#coc#check but when I tried to open a terminal with :terminal then it will throw an error with E475: Invalid value for argument cmd: 'C:WindowsSystem32cmd.exe' is not executable

Now, after I found that out, I changed my .vimrc and my .minimalvimrc to:

set shell=cmd

Which satisfy both health#coc#check and also correctly open the terminal. Why that is the case I have no idea, and maybe something that the neovim team would like to take a look at. I can potentially report this to them if I can't find out why.

However, even with that change, the vimtex bug still exist. I still get:

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG SEE HERE: 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 2, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 3, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 4, $shell:  C:\msys64\usr\bin\bash.exe
['/usr/bin/bash: /s: No such file or directory']

And yes that is with the .minimalvimrc :

set nocompatible
set runtimepath^=C:\\Users\\XXX\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vimtex
filetype plugin indent on
syntax enable
" Add relevant options and VimTeX configuration below.
" Possibly add settings like these (whatever is required to reproduce the
" issue)
set shell=cmd
let &shellcmdflag="/s /c"
set shellxquote=\"

" Run something that fails with the same issue as the original problem:
" Current hypothesis is that this is "systeminfo", but that needs
" verification.
echo vimtex#jobs#capture('systeminfo')

quitall

As for the question of which &shell is being set, here's what I got when I open a .tex file:

:verbose set shell
  shell=cmd
        Last set from ~/.vimrc line 6

@stanle-cs
Copy link
Author

stanle-cs commented Nov 5, 2022

So, I tried to modify neovim.vim like this:

function! s:neovim_win_capture(cmd) abort " {{{1
  unsilent echo 'DEBUG SEE HERE: 1, $shell: ' $shell
  let s:saveshell = [&shell, &shellcmdflag, &shellslash]
  set shell& shellcmdflag& shellslash&
  "Debug
  set shell=cmd
  let &shellcmdflag="/s /c"
  set shellxquote=\""
  "End Debug

  unsilent echo 'DEBUG SEE HERE: 2, $shell: ' $shell
  let l:output = systemlist('cmd /s /c "' . a:cmd . '"')

  unsilent echo 'DEBUG SEE HERE: 3, $shell: ' $shell
  let [&shell, &shellcmdflag, &shellslash] = s:saveshell

  unsilent echo 'DEBUG SEE HERE: 4, $shell: ' $shell

  return l:output
endfunction

This will change the result of .minimalvimrc to:

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG SEE HERE: 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 2, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 3, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 4, $shell:  C:\msys64\usr\bin\bash.exe
['', 'Host Name:                 USSNFL123', 'OS Name:                   Microsoft Windows 10 Pro', 'OS Version:                10.0.19044 N/A Build 19044', 'OS Manufacturer:           Microsoft Corporation', 'OS Configuration:          Standalone Workstation', 'OS Build
 Type:             Multiprocessor Free
[Redacted since this is a work laptop]
]

(I hid the data since this is a work laptop, but you get the point).
Now that will give a good VimtexInfo result:

System info:
   OS: USSNFL123 (Microsoft Windows 10 Pro)
   Vim version: NVIM v0.9.0-dev-206+gc3aba403c
   Has clientserver: true
   Servername: \\.\pipe\nvim.30676.0

But, when I try to do \ll I still get:

  1   /usr/bin/bash: /s: No such file or directory

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

So, I tried to modify neovim.vim like this: …

This will change the result of .minimalvimrc to:

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG SEE HERE: 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG SEE HERE: 2, $shell:  C:\msys64\usr\bin\bash.exe

This does not seem right. It's inconsistent. You specifically changed shell before the DEBUG SEE HERE: 2 print statement, but it still outputs the bash.exe variant. Could you please check this and update your comments if I'm right?

But, when I try to do \ll I still get:

Yes, there are more ways to run a process. Let's focus on where we are first. If I can figure out what is actually going wrong here, we might be able to fix it.


Here's a new minimal example that should, as far as I can understand, be equivalent to the one you are currently using:

set nocompatible
filetype plugin indent on
syntax enable

echo 'DEBUG 1, $shell: ' &shell
set shell=cmd
let &shellcmdflag="/s /c"
set shellxquote=\"

" This SHOULD be different that above!
echo 'DEBUG 2, $shell: ' &shell

let s:saveshell = [&shell, &shellcmdflag, &shellslash]
set shell& shellcmdflag& shellslash&

" This SHOULD be as debug 1!
echo 'DEBUG 3, $shell: ' &shell

let s:output = systemlist('cmd /s /c "' . a:cmd . '"')

let [&shell, &shellcmdflag, &shellslash] = s:saveshell

" This SHOULD be as debug 2!
echo 'DEBUG 4, $shell: ' &shell

for s:x in s:output
  echo s:x
endfor

quitall

@stanle-cs
Copy link
Author

stanle-cs commented Nov 6, 2022

Yeah you're right, this is strange. I tried the following to confirm:

   14 function! s:neovim_win_capture(cmd) abort " {{{1
   13   let s:saveshell = [&shell, &shellcmdflag, &shellslash]
   12   set shell& shellcmdflag& shellslash&
   11
   10   set shell=cmd
    9   let &shellcmdflag="/s /c"
    8   set shellxquote=\"
    7   unsilent echo 'DEBUG change shell, $shell: ' $shell
    6
    5   let l:output = systemlist('cmd /s /c "' . a:cmd . '"')
    4
    3   let [&shell, &shellcmdflag, &shellslash] = s:saveshell
    2
    1   return l:output
  170 endfunction

And get

$ vim --headless --clean -u ~/.minimalvimrc
DEBUG change shell, $shell:  C:\msys64\usr\bin\bash.exe
['', 'Host Name:                 USSNFL123', 'OS Name:                   Microsoft Windows 10 Pro', 
[Redacted]'

So yeah, $shell stays the same after the set shell= call!
I tried to change it to let &shell='cmd' but the same thing happened.
As for the new test, looks like we need to define that a:cmd somehow. I'm not familiar with vimscript enough to change it. Using this .minimalvimrc2:

  1   set nocompatible
    1 filetype plugin indent on
    2 syntax enable
    3
    4 echo 'DEBUG 1, $shell: ' &shell
    5 set shell=cmd
    6 let &shellcmdflag="/s /c"
    7 set shellxquote=\"
    8
    9 " This SHOULD be different that above!
   10 echo 'DEBUG 2, $shell: ' &shell
   11
   12 let s:saveshell = [&shell, &shellcmdflag, &shellslash]
   13 set shell& shellcmdflag& shellslash&
   14
   15 " This SHOULD be as debug 1!
   16 echo 'DEBUG 3, $shell: ' &shell
   17
   18 let s:output = systemlist('cmd /s /c "' . a:cmd . '"')
   19
   20 let [&shell, &shellcmdflag, &shellslash] = s:saveshell
   21
   22 " This SHOULD be as debug 2!
   23 echo 'DEBUG 4, $shell: ' &shell
   24
   25 for s:x in s:output
   26   echo s:x
   27 endfor
   28
   29 quitall

Output:

$ vim --headless --clean -u ~/.minimalvimrc2
DEBUG 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG 2, $shell:  cmd
DEBUG 3, $shell:  C:\msys64\usr\bin\bash.exe
Error detected while processing C:\msys64\home\XXX\.minimalvimrc2:
line   19:
E121: Undefined variable: a:cmd
E116: Invalid arguments for function systemlist
DEBUG 4, $shell:  cmd
line   26:
E121: Undefined variable: s:output

Do I need to turn cache persistence off in my .minimalvimrc too?

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Yeah you're right, this is strange. I tried the following to confirm: …

So yeah, $shell stays the same after the set shell= call! I tried to change it to let &shell='cmd' but the same thing happened.

Very strange, indeed!

As for the new test, looks like we need to define that a:cmd somehow.

Sorry, my mistake. It should be let s:output = systemlist('cmd /s /c "systeminfo"').

Using this .minimalvimrc2: …

Output:

$ vim --headless --clean -u ~/.minimalvimrc2
DEBUG 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG 2, $shell:  cmd
DEBUG 3, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG 4, $shell:  cmd

Well, if we disregard the errors, it now seems to echo as expected. So that's quite good, I would say. Let me know the output after fixing the a:cmd as explained.

Do I need to turn cache persistence off in my .minimalvimrc too?

No, that's not necessary. The cache is only relevant for the vimtex#jobs#cached function, not for the #capture variant that we are considering for now.

@stanle-cs
Copy link
Author

Ah I see, with that fix we have this ouput:

$ vim --headless --clean -u ~/.minimalvimrc2
DEBUG 1, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG 2, $shell:  cmd
DEBUG 3, $shell:  C:\msys64\usr\bin\bash.exe
DEBUG 4, $shell:  cmd
/usr/bin/bash: /s: No such file or directory

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Cool. I believe we are getting close to understanding the real issue here.

Can you now run this one?

set nocompatible

verbose set shell
for s:x in systemlist('cmd /s /c "systeminfo"')
  echo s:x
endfor

set shell=cmd
let &shellcmdflag="/s /c"
set shellxquote=\"

verbose set shell
for s:x in systemlist('cmd /s /c "systeminfo"')
  echo s:x
endfor

quitall

My hypothesis is that the first systemlist will not work, whereas the second one will. If I'm right, could you also check if you need to change both &shellcmdflag and shellxquote for it to work, or if only one or the other, or none of them, are required?

@stanle-cs
Copy link
Author

stanle-cs commented Nov 6, 2022

You're correct, the result:

 vim --headless --clean -u ~/.minimalvimrc3
  shell=C:\msys64\usr\bin\bash.exe
/usr/bin/bash: /s: No such file or directory
  shell=cmd
        Last set from ~/.minimalvimrc3 line 8

Host Name:                 USSNFL123
OS Name:                   Microsoft Windows 10 Pro
[redacted the rest]

And neither &shellcmdflag nor shellxquote is required.

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Ok. Let's go back to this example:

set nocompatible
set runtimepath^=C:\\Users\\XXX\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vimtex
filetype plugin indent on
syntax enable

let &shell='"C:\\Windows\\System32\\cmd.exe"'
"let &shellcmdflag="/s /c"
"set shellxquote=\"

echo vimtex#jobs#capture('systeminfo')

quitall

Does it work if you change the s:neovim_win_capture to the following?

function! s:neovim_win_capture(cmd) abort " {{{1
  "let s:saveshell = [&shell, &shellcmdflag, &shellslash]
  "set shell& shellcmdflag& shellslash&

  let l:output = systemlist('cmd /s /c "' . a:cmd . '"')

  "let [&shell, &shellcmdflag, &shellslash] = s:saveshell

  return l:output
endfunction

@stanle-cs
Copy link
Author

With jobs/neovim.vim:

 156 function! s:neovim_win_capture(cmd) abort " {{{1
    1   "let s:saveshell = [&shell, &shellcmdflag, &shellslash]
    2   "set shell& shellcmdflag& shellslash&
    3
    4   "let &shell='cmd'
    5   "let &shellcmdflag="/s /c"
    6   "set shellxquote=\"
    7   "unsilent echo 'DEBUG change shell, $shell: ' $shell
    8
    9   let l:output = systemlist('cmd /s /c "' . a:cmd . '"')
   10
   11   "let [&shell, &shellcmdflag, &shellslash] = s:saveshell
   12
   13   return l:output
   14 endfunction

and .minimalvimrc:

  1   set nocompatible
    1 set runtimepath^=C:\\Users\\XX\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vimtex
    2 filetype plugin indent on
    3 syntax enable
    4
    5 let g:vimtex_cache_persistent = 0
    6 " Add relevant options and VimTeX configuration below.
    7 " Possibly add settings like these (whatever is required to reproduce the
    8 " issue)
    9 set shell=cmd
   10 "let &shellcmdflag="/s /c"
   11 "set shellxquote=\"
   12
   13 " Run something that fails with the same issue as the original problem:
   14 " Current hypothesis is that this is "systeminfo", but that needs
   15 " verification.
   16 echo vimtex#jobs#capture('systeminfo')
   17
   18 quitall

output:

$  vim --headless --clean -u ~/.minimalvimrc
['', 'Host Name:                 USSNFL123', 'OS Name:                   Microsoft Windows 10 Pro', 
[redacted]
]

So yeah looks like it works now.

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

I believe the final piece of this puzzle is to recognize MSYS2 in a good way.

Or, thinking about it, perhaps a better way is to do this:

function! s:neovim_win_capture(cmd) abort " {{{1
  let s:saveshell = [&shell, &shellcmdflag, &shellslash]
  let &shell = 'cmd.exe'
  let &shellcmdflag = '/s /c'
  set shellslash

  let l:output = systemlist('cmd /s /c "' . a:cmd . '"')

  let [&shell, &shellcmdflag, &shellslash] = s:saveshell

  return l:output
endfunction

@stanle-cs
Copy link
Author

You're right! With the new version of neovim_win_capture the output of VimtexInfo is now correct:

  1   System info:
    1   OS: USSNFL123 (Microsoft Windows 10 Pro)
    2   Vim version: NVIM v0.9.0-dev-206+gc3aba403c
    3   Has clientserver: true
    4   Servername: \\.\pipe\nvim.20016.0

I tried it with both the MSYS2 shell and the Command Prompt shell. Works perfectly, but seems like neovim hang for a split second before the info is outputed.

One curious thing to note however, \ll works on the Command Prompt shell but not MSYS2 shell.

By the way, thank you very much for your dedication and help lervag!

lervag added a commit that referenced this issue Nov 6, 2022
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

You're right! With the new version of neovim_win_capture the output of VimtexInfo is now correct: …

Great!

One curious thing to note however, \ll works on the Command Prompt shell but not MSYS2 shell.

Yes, that's expected.

I've pushed an update where I've refactored this shell config changing into separate functions. Can you update to latest version, then consider these lines:

function! vimtex#jobs#neovim#shell_default() abort " {{{1
let s:saveshell = [&shell, &shellcmdflag, &shellslash]
set shell& shellcmdflag& shellslash&
endfunction
" }}}1

Now, apply the same kind of patch as before. I believe things should now work for you as expected, also for \ll. Can you confirm that?


By the way, thank you very much for your dedication and help lervag!

Glad to help. As you may have realized, I don't use Windows, and so I require the help from users to make things work well on Windows. :)

@stanle-cs
Copy link
Author

Hi lervag,

It works perfectly now with the patch for jobs/neovim.vim:

   26 function! vimtex#jobs#neovim#shell_default() abort " {{{1
   27   let s:saveshell = [&shell, &shellcmdflag, &shellslash]
   28   "set shell& shellcmdflag& shellslash&
   29   let &shell = 'cmd.exe'
   30   let &shellcmdflag = '/s /c'
   31   set shellslash
   32 endfunction

The compiler now starts in continuous mode successfully.

Thank you very much for making this work! I'm now able to use vimtex at work on the MSYS2 shell with no admin right. I'm sure this will come in handy to someone else too!

@stanle-cs
Copy link
Author

FYI, found out that only set shell=cmd is needed:

  27  function! vimtex#jobs#neovim#shell_default() abort " {{{1
    1   let s:saveshell = [&shell, &shellcmdflag, &shellslash]
    2   "set shell& shellcmdflag& shellslash&
    3   let &shell = 'cmd.exe'
    4 endfunction

lervag added a commit that referenced this issue Nov 6, 2022
This seems necessary to make things work on MSYS2.

refer: #2554
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

It works perfectly now with the patch for jobs/neovim.vim: …

Thank you very much for making this work! I'm now able to use vimtex at work on the MSYS2 shell with no admin right. I'm sure this will come in handy to someone else too!

Glad to hear it! But I don't think the issue is resolved yet, because you should not have to make custom changes on your end. Instead, I think I'll rather make this change directly in VimTeX and push it to everyone. I believe it will not break anything for anyone, while it will make things work as expected on MSYS2.

FYI, found out that only set shell=cmd is needed:

Thanks! Then I'll only change that one.

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

I believe my latest update should fix this without you needing to do anything. Please test and confirm!

@stanle-cs
Copy link
Author

Just tested the new change, you may have missed something as without let g:vimtex_cache_persistent = 0 the same error appeared. With let g:vimtex_cache_persistent = 0 however it works.

I noticed that if I didn't have these lines:

    3 "set shell=cmd
    4 "let &shellcmdflag="/s /c"
    5 "set shellxquote=\"

Then \ll and \lv won't open my external viewer (sumatraPDF). So maybe you do need all of them in the fix. My apology for not testing everything before I claim that only set shell=cmd is needed.

@stanle-cs stanle-cs reopened this Nov 6, 2022
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Please do :VimtexClearCache ALL.

Are you sure about shellxquote? I'm pushing an update where I add shellcmdflag now, but I'll await your reply before adding shellxquote as well.

@stanle-cs
Copy link
Author

stanle-cs commented Nov 6, 2022

scratch that, I just forgot to run :VimtexClearCache ALL.

Everything works now if I have:

    3 set shell=cmd
    4 let &shellcmdflag="/s /c"
    5 set shellxquote=\"

in my .vimrc. Without them, only \ll works.

@stanle-cs
Copy link
Author

One sec let me check each of the three in my .vimrc first before I give you the details.

lervag added a commit that referenced this issue Nov 6, 2022
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

I've pushed an update now, please update. I believe things should now work as expected.

Btw, a minor side comment: It is better if you write your code listings without the line numbers. They are not interesting and only makes it harder to copy the lines. :)

@stanle-cs
Copy link
Author

With the newest update, no changes made to the jobs/neovim.vim file:
In my ~/.vimrc:

  • No "let g:vimtex_cache_persistent = 0 needed.
  • Without all three : Compilation works, no viewer spawned, \lv does not spawn viewer.
  • With only set shell=cmd: Compilation works, SumatraPDF viewer spawned.
  • Without set shell=cmd, and each of set shellxquote=\" or let &shellcmdflag="/s /c" alone: Compilation works, no viewer spawned, \lv does not work.
  • With both set shellxquote=\" or let &shellcmdflag="/s /c": Compilation works, no viewer spawned, \lv does not work.

And sorry for about the line numbers, I copied the line directly from the terminal and I had set number relativenumber on. Will try to cut them out next time!

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Huh, that's strange. In the latest version, VimTeX should override your values of shell and shellcmdflag, so it should not matter what you set them to. That is, it does not make sense to me at all that changing these values in your vimrc will change the results! This is specifically because of the following code, which overrides your personal config:

function! vimtex#jobs#neovim#shell_default() abort " {{{1
let s:saveshell = [&shell, &shellcmdflag, &shellslash]
let &shell = 'cmd.exe'
let &shellcmdflag="/s /c"
set shellslash&
endfunction

Consider me confused...

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

In the case where \lv does not work: what's the output of \li, speficially the lines about the viewer?

@stanle-cs
Copy link
Author

It looks like this:

  System info:
    OS: USSNFL123 (Microsoft Windows 10 Pro)
    Vim version: NVIM v0.9.0-dev-206+gc3aba403c
    Has clientserver: true
    Servername: \\.\pipe\nvim.21860.0

  VimTeX project: ttd_upstream
    base: ttd_upstream.tex
    root: C:\msys64\home\XX\LaTeX\ttd_upstream
    tex: C:\msys64\home\XX\LaTeX\ttd_upstream\ttd_upstream.tex
    main parser: current file verified
    document class: article
    compiler: latexmk
      engine: -pdf
      options:
        -xelatex
        -file-line-error
        -synctex=1
        -interaction=nonstopmode
      build_dir: ./build
      callback: 1
      continuous: 1
      executable: latexmk.exe
    viewer: General
    qf method: LaTeX logfile

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

I think perhaps we should take a step back, again. Would you be able to create a minimal vimrc file for this specific case, e.g.:

" test.vim
set nocompatible
set runtimepath^=C:\\Users\\XX\\AppData\\Local\\nvim-data\\plugged\\vimtex
filetype plugin indent on
syntax enable

" Any relevant config goes here (e.g. SumatraPDF stuff)

silent edit test.tex

Also, specific steps to reproduce the error, e.g.:

  1. Run nvim --clean -u test.vim
  2. \ll to start compilation
  3. Observe viewer opens or not?
  4. \lv - observe viewer opens or not?
  5. Report the viewer: part of the output of \li (after step 4!)

@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Also, please report the minimal vimrc you use. Notice that you now should not use the --headless option.

@stanle-cs
Copy link
Author

Done! Here are the details:
Test file: .minimalvimrc4:

  " test.vim
  set nocompatible
  set runtimepath^=C:\\Users\\XX\\AppData\\Local\\nvim-data\\site\\pack\\packer\\start\\vimtex
  filetype plugin indent on
  syntax enable

  " Any relevant config goes here (e.g. SumatraPDF stuff)
  set conceallevel=1
  let g:textconceal='abdmg'
  let g:vimtex_view_general_viewer = 'SumatraPDF.exe'
  let g:vimtex_view_general_options = '-reuse-instance -forward-search @tex @line @pdf'
  let g:vimtex_compiler_method="latexmk"
  let g:vimtex_compiler_latexmk = {
          \ 'build_dir' : './build',
          \ 'executable' : 'latexmk.exe',
          \ 'options' : [
          \   '-xelatex',
          \   '-file-line-error',
          \   '-synctex=1',
          \   '-interaction=nonstopmode',
          \ ],
          \}


  silent edit test.tex
  1. Run vim --clean -u ~/.minimalvimrc4:
  2. Type in the following and save:
\documentclass{article}
\begin{document}
    Hello world
\end{document}
  1. \ll to start compilation: viewer does not open.
VimTeX: Compilation completed
  1. \lv: viewer does not open.
  2. \li info:
viewer: General
    job:
      pid: -
      cmd: SumatraPDF.exe -reuse-instance -forward-search "C:\msys64\home\XX\LaTeX\ttd_upstream\test.tex" 1 "C:\msys64\home\XX\LaTeX\ttd_upstream\build\test.pdf"

Interestingly, if I do a :VimtexClearCache ALL first then do \li then the output is:

viewer: General

without the rest of the info.

@stanle-cs
Copy link
Author

stanle-cs commented Nov 6, 2022

EDIT: Scratch that, it is actually because I added set shell=cmd to .minimalvimrc4 as a test and forgot about it. So the real interesting thing is that if my .vimrc has set shell=cmd at all then the viewer can be spawned.

Interestingly, if I change jobs/neovim.vim to:

  function! vimtex#jobs#neovim#shell_default() abort " {{{1
    let s:saveshell = [&shell, &shellcmdflag, &shellslash]
    "let &shell = 'cmd.exe'
    set shell=cmd
    let &shellcmdflag="/s /c"
    set shellslash&
  endfunction

  " }}}1

Then the test execute just fine with viewer spawned.

@lervag
Copy link
Owner

lervag commented Nov 8, 2022

Done!

Sorry about the late reply, been busy.

Here are the details: Test file: .minimalvimrc4: …

I notice some bad stuff in your vimrc file. Let me fix that for you: 😄

2d1
< let g:textconceal='abdmg'
5c4
< let g:vimtex_compiler_method="latexmk"
---
> let g:vimtex_compiler_latexmk_engines = { '_': '-xelatex' }
9,14d7
<         \ 'options' : [
<         \   '-xelatex',
<         \   '-file-line-error',
<         \   '-synctex=1',
<         \   '-interaction=nonstopmode',
<         \ ],

To explain:

  • g:textconceal is not correct (you probably mean g:tex_conceal), and is also not relevant for VimTeX.
  • Since you did not change g:vimtex_compiler_method from the default, it is not necessary.
  • And finally, the -xelatex option should be specified with g:vimtex_compiler_latexmk_engines (see one of the final notes under :help vimtex_compiler_latexmk).

So the real interesting thing is that if my .vimrc has set shell=cmd at all then the viewer can be spawned.

So, what you are saying is that everything works as expected now if you add set shell=cmd in your .vimrc file? But if you remove it, then it does not work?

@lervag
Copy link
Owner

lervag commented Nov 8, 2022

I suspect the problem may be here:

if !empty(self.cwd)
let l:options.cwd = self.cwd
endif
let self.job = jobstart(self.cmd, l:options)
return self
endfunction

Could you try change line 64 this to:

  call vimtex#jobs#neovim#shell_default()
  let self.job = jobstart(self.cmd, l:options)
  call vimtex#jobs#neovim#shell_restore()

lervag added a commit that referenced this issue Nov 8, 2022
@lervag
Copy link
Owner

lervag commented Nov 8, 2022

I just pushed that change, as I believe it should be necessary regardless - could you please update and test? (No need to make any local changes first).

@stanle-cs
Copy link
Author

Hi levarg, sorry I haven't checked this in 2 days.

I tried the newest update, and everything is working as expected with no modifications needed. It has been a cool journey getting to the bottom of it. I thank you for the dedication you have for this project.

Also appreciate the time you take to fix my settings!

I will close the topic now as I believe this is completely resolved.

@lervag
Copy link
Owner

lervag commented Nov 10, 2022

Great, I'm glad to hear things work as expected now! Also glad to hear you've enjoyed working with me on resolving things. Thanks for hanging in! Second hand debugging can sometimes require some patience :)

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

No branches or pull requests

2 participants